這個做法應(yīng)該是圖方便的加密解密做法。按你的C#代碼來改的話是這樣的。

創(chuàng)新互聯(lián)專注于豐縣企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城系統(tǒng)網(wǎng)站開發(fā)。豐縣網(wǎng)站建設(shè)公司,為豐縣等地區(qū)提供建站服務(wù)。全流程按需定制,專業(yè)設(shè)計,全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
'Imports System.IO
Public Function MapPath(ByVal virtualPath As String) As String
' Return System.Web.Hosting.MapPath(virtualPath)
' 猜想是這個 MapPath 函數(shù)
' 如果不是那就自己還原原來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) ' 把圖片讀到字節(jié)數(shù)組中
s.Close()
Dim str As String = Convert.ToBase64String(by) ' 把字節(jié)數(shù)組轉(zhuǎn)換成字符串
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) ' 把字符串讀到字節(jié)數(shù)組中
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
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指vb6還是vb.net,你是問語法還是轉(zhuǎn)碼后的圖片
vb.net和c#都會預(yù)編譯程clr文件,雙擊exe執(zhí)行的其實(shí)是clr,沒有任何區(qū)別
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參數(shù)是GB2312字符串,函數(shù)返回UTF8字節(jié)數(shù)組
'容易,用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
在access數(shù)據(jù)庫里將字段的類型設(shè)置為ole對象
Public img As Byte() '圖片處理用的字節(jié)數(shù)組
img=My.Computer.FileSystem.ReadAllBytes(filePath)'filePath是你圖片文件的路徑
剩下的就是數(shù)據(jù)庫插入操作了
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)
'向數(shù)據(jù)庫添加存儲了圖片數(shù)據(jù)的二進(jìn)制數(shù)組
comm.Parameters.Add("@image",?_
OleDb.OleDbType.Binary,?img.Length).Value?=?img
If?cn.State?=?ConnectionState.Closed?Then?cn.Open()?'打開數(shù)據(jù)庫連接
comm.ExecuteNonQuery()?'執(zhí)行數(shù)據(jù)庫命令
If?cn.State?=?ConnectionState.Open?Then?cn.Close()?'關(guān)閉數(shù)據(jù)庫連接
MessageBox.Show("圖片成功保存到數(shù)據(jù)庫",?"完成",?MessageBoxButtons.OK,?MessageBoxIcon.Information)
網(wǎng)頁標(biāo)題:vb.net圖片編碼,vb中顯示圖片的代碼怎么寫
本文來源:http://chinadenli.net/article47/dseppej.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、網(wǎng)站排名、網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航、用戶體驗(yàn)、關(guān)鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)