在access數(shù)據(jù)庫里將字段的類型設(shè)置為ole對象
十多年的彌勒網(wǎng)站建設(shè)經(jīng)驗(yàn),針對設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。網(wǎng)絡(luò)營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整彌勒建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)公司從事“彌勒網(wǎng)站設(shè)計(jì)”,“彌勒網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
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)
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
'容易,用api,查一查SetBitmapBits
'新建工程,增加一個(gè) command button , 一個(gè) 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
一、二進(jìn)制文件讀寫
1、寫二進(jìn)制數(shù)據(jù)到指定目錄
==將barray字節(jié)數(shù)組中的數(shù)據(jù)創(chuàng)建在strFilename目錄文件下,存儲格式為二進(jìn)制,F(xiàn)alse表示不添加,直接覆蓋創(chuàng)建。
2、從指定路徑下讀取二進(jìn)制數(shù)據(jù)到數(shù)組
==將目錄中的文件讀取到barry字節(jié)數(shù)組中,即讀取二進(jìn)制文件。
二、字符文件的讀寫
1、 將txtFile控件中的字符寫到srtFileName指定目錄,以創(chuàng)建方式。
2、從srtFileName目錄中的文件讀取到txtFile控件