资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net图片转二进制 vb二进制转十六进制代码

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

Picture1.Refresh

End Sub

在VB.net中如何将图片转换成二进制保存到Accees中

在access数据库里将字段的类型设置为ole对象

Public img As Byte() '图片处理用的字节数组

img=My.Computer.FileSystem.ReadAllBytes(filePath)'filePath是你图片文件的路径

剩下的就是数据库插入操作了

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 = 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 图片转换二进制代码

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图片转二进制 vb二进制转十六进制代码
文章出自:http://cdkjz.cn/article/dddiedg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220