在VB.net中如何将图片转换成二进制保存到Accees中在access数据库里将字段vb.net图片二进制的类型设置为ole对象
Public img As Byte() '图片处理用vb.net图片二进制的字节数组
img=My.Computer.FileSystem.ReadAllBytes(filePath)'filePath是vb.net图片二进制你图片文件vb.net图片二进制的路径
剩下的就是数据库插入操作vb.net图片二进制了
Dim cn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Data.mdb")
Dim comm As OleDb.OleDbCommand
comm = New OleDb.OleDbCommand( _
"INSERT INTO Photo(BuFan_F,PhotoNo,Photo) Values('"Me.CobBuFan.Text.Trim"','"Me.txtNo.Text.Trim"',@image)", cn)
'向数据库添加存储了图片数据的二进制数组
comm.Parameters.Add("@image", _
OleDb.OleDbType.Binary, img.Length).Value = https://www.04ip.com/post/img
If cn.State = ConnectionState.Closed Then cn.Open() '打开数据库连接
comm.ExecuteNonQuery() '执行数据库命令
If cn.State = ConnectionState.Open Then cn.Close() '关闭数据库连接
MessageBox.Show("图片成功保存到数据库", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information)
vb.net 将文件转化成二进制首先引入System.IO命名空间
Imports System.IO
然后使用文件流来读入数组:
Dim bytes() As Byte
Using fs As New FileStream(文件路径,FileMode.Open)
ReDim bytes(fs.Length-1)
fs.Read(bytes,0,fs.Length)
fs.Close()
End Using
这样bytes就是整个文件的所有字节了
从字节生成Image:
Dim img As Image = Image.FromStream(New MemoryStream(bytes))
img就是图片了
vb.net2003如何将二进制流转换成图片显示在网页上?好像没有什么好办法,你只有不用数值型的文本框,还是改用字符型的,这样不论点击哪里光标都会出现在最前面,然后在代码中用val()函数将其转换为数值型
vb.net 图片转换二进制代码Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyStream As New System.IO.MemoryStream
Me.PictureBox1.Image.Save(MyStream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim MyBytes(MyStream.Length) As Byte
MyStream.Read(MyBytes, 0, MyStream.Length)
MyStream.Close()
Dim strText As String
strText = BitConverter.ToString(MyBytes)
Me.TextBox1.Text = strText
End Sub
vb.net如何将图片转二进制'容易,用api , 查一查SetBitmapBits
'新建工程,增加一个 command button , 一个 picture box , 将图片加载到 picture box.
'将代码粘贴到 Form1
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Dim PicBits() As Byte, PicInfo As BITMAP, Cnt As Long
Private Sub Command1_Click()
'Get information (such as height and width) about the picturebox
GetObject Picture1.Image, Len(PicInfo), PicInfo
'reallocate storage space
ReDim PicBits(1 To PicInfo.bmWidth * PicInfo.bmHeight * 3) As Byte
'Copy the bitmapbits to the array
GetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
'Invert the bits
For Cnt = 1 To UBound(PicBits)
PicBits(Cnt) = 255 - PicBits(Cnt)
Next Cnt
'Set the bits back to the picture
SetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
'refresh
推荐阅读
- 独立开发游戏大赛,独立开发游戏有多难
- 武汉网站如何优化推广,直通车推广如何优化
- 为什么微信视频接不了,为什么微信视频接不了电话
- 爆笑游戏动作,搞笑游戏动画
- 会go语言的金融学生就业 金融专业编程学什么语言
- 29寸电视怎么改串联主机,29寸电视怎么没有了
- chatgpt的实现原理,tspot原理
- pve虚拟机无法自动升级,pve虚拟机无法自动升级怎么回事
- c语言cuda核函数 c语言内核深度解析