vb.net图片编码,vb中显示图片的代码怎么写
vb.net(2008)把图片(或其它类型文件)转换成字符串存入.txt文件中,并从.txt中读出生成图片
这个做法应该是图方便的加密解密做法。按你的C#代码来改的话是这样的。
创新互联专注于丰县企业网站建设,成都响应式网站建设公司,商城系统网站开发。丰县网站建设公司,为丰县等地区提供建站服务。全流程按需定制,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务
'Imports System.IO
Public Function MapPath(ByVal virtualPath As String) As String
' Return System.Web.Hosting.MapPath(virtualPath)
' 猜想是这个 MapPath 函数
' 如果不是那就自己还原原来C#代码里的那个MapPath
End Function
Public Sub GetImage()
Dim s As System.IO.Stream = System.IO.File.Open(MapPath("33.jpg"), System.IO.FileMode.Open)
Dim leng As Integer = 0
If s.Length Int32.MaxValue Then
leng = s.Length
End If
Dim by(leng) As Byte
s.Read(by, 0, leng) ' 把图片读到字节数组中
s.Close()
Dim str As String = Convert.ToBase64String(by) ' 把字节数组转换成字符串
Dim sw As System.IO.StreamWriter = System.IO.File.CreateText(MapPath("11.txt")) ' 存入11.txt文件
sw.Write(str)
sw.Close()
sw.Dispose()
End Sub
' 把字符串还原成图片
Public Sub CreateImg()
Dim sr As New System.IO.StreamReader(MapPath("11.txt"))
Dim s As String = sr.ReadToEnd()
sr.Close()
Dim buf As Byte() = Convert.FromBase64String(s) ' 把字符串读到字节数组中
Dim ms As New System.IO.MemoryStream(buf)
Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(ms)
img.Save(MapPath("12.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg)
ms.Close()
ms.Dispose()
End Sub
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
图片转成base64编码,VB和C#是否有区别
这里的vb指vb6还是vb.net,你是问语法还是转码后的图片
vb.net和c#都会预编译程clr文件,双击exe执行的其实是clr,没有任何区别
vb.net 如何将编码GB2312转成UTF8
Imports System.Text
Public Function StringAsUtf8Bytes(ByVal strData As String) As Byte()
Dim bytes() As Byte
bytes = Encoding.UTF8.GetBytes(strData)
Return bytes
End Function
说明:strData参数是GB2312字符串,函数返回UTF8字节数组
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图片编码,vb中显示图片的代码怎么写
网页URL:http://ybzwz.com/article/dseppej.html