我没有用过Access 存取图片,但是用Sql Server 里我是先将数据库里的图片字段恢复成临时文件,然后用PICTURE1.PICTURE = LoadPicture(App.Path & 临时文件名)来实现的如果没说清除再问我
解决方案 »
- VB 滚动条 各位大侠帮忙,急急
- 怎么取得DX游戏中屏幕某个像素点的RGB值?
- 有没有办法获取到页面中的<span>里面的值?送200分
- 请教各位大虾Datagrid和Msflexgrid有什么区别啊
- 请问哪里有VB的,关于MP3,WAV等多媒体文件的转换源程序或资料?
- 如何编写代码把图片剪裁后再加载到图片控件?
- 什么样的程序不需要安装就可以运行,如何制作这样的程序?(在线)
- 各位大哥大姐,如何算出一个正在打开的excel的sheet个数,并判断sheet是否重名?着急!!
- Vb2008 文本数据计算处理问题
- 开玩笑,中国无人能答?!请教关于多媒体数据流实时采集的问题
- 100分请教:VB中如何直接发送邮件或调用Outlook Express?
- 请问如何连接到别的计算机上的SQL server 2000 ///100分
参数:strPicField 数据库里存图片的字段名,rs 是ADO记录集
Public Function getPicture(strPicField As String, ByVal rs As ADODB.Recordset) As Boolean
'从数据库读取图片,生成磁盘文件
Const BlockSize = 15000
Dim ByteData() As Byte '以二进制形式存储图片的字节数组
Dim DestFileNum As Integer
Dim DiskFile As String
Dim FileLength As Long '图片文件的长度
Dim Numblocks As Integer '图片的块数
Dim LeftOver As Long '剩余部分
Dim i As Integer
On Error GoTo Line1
'删除已存在的图形文件
DiskFile = App.Path & "\temp.bmp"
If Len(Dir$(DiskFile)) > 0 Then
Kill DiskFile
End If
'把图片文件分解成几部分
DestFileNum = FreeFile
FileLength = rs.Fields(strPicField).ActualSize
Numblocks = FileLength \ BlockSize
LeftOver = FileLength Mod BlockSize
'打开文件,开始按块存入数据库
Open DiskFile For Binary As DestFileNum
rs.Move 0, adBookCurrent
ByteData() = rs.Fields(strPicField).GetChunk(LeftOver)
Put DestFileNum, , ByteData() For i = 1 To Numblocks
ByteData() = rs.Fields(strPicField).GetChunk(BlockSize)
Put DestFileNum, , ByteData()
Next i Close DestFileNum getPicture = TrueLine1:
End Function
你还可以在CSDN中搜索到很多关于在数据库中存储图片的文章,自己看看吧
Private Sub DBOpen()
'open the database with ADO
MYcon.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0; DATA SOURCE=" & App.Path + "/DBpic.MDB"
MYrs.Open "PICTABLE", MYcon, 1, 3End Sub
'Close the open database
Private Sub DBClose()
MYrs.Close
MYcon.Close
Set MYrs = Nothing
Set MYcon = Nothing
End SubPrivate Sub SaveInto(ByVal strPath As String)Dim lngFileLength As Long 'the length of the file
Dim lngBlockCount As Long 'the number of total whole block
Dim lngLastBlock As Integer 'the length of the last block
Dim lngBlockIndex As Long 'the index of each block
Dim ByteGet() As Byte '用于传送数据的二进制数组
Dim FileNum As Integer 'return the file number which the next file will use
Dim strFilepath As String
strFilepath = strPath
FileNum = FreeFile()
Open strFilepath For Binary Access Read As #FileNum
lngFileLength = LOF(FileNum) '返回一个 Long,表示用 Open 语句打开的文件的大小,该大小以字节为单位。
lngBlockCount = lngFileLength \ lngBlockSize
lngLastBlock = lngFileLength Mod lngBlockSize
MYrs.AddNew
MYrs.Fields("size") = lngFileLength
MYrs.Fields("date") = Date
MYrs.Fields("name") = Trim(Text1)
ReDim ByteGet(lngBlockSize)
For lngBlockIndex = 1 To lngBlockCount
Get #FileNum, , ByteGet()
MYrs.Fields("pic").AppendChunk ByteGet()
Next
If lngLastBlock > 0 Then
ReDim ByteGet(lngLastBlock)
Get #FileNum, , ByteGet()
MYrs.Fields("pic").AppendChunk ByteGet()
End If
MYrs.Update
Close #FileNum
End SubPrivate Sub ShowImg(ByVal RecordPoint As Long)
On Error Resume NextDim temp_path As String
Dim temp_file As String
Dim length As Long
Dim lngFileLength As Long 'the length of the file
Dim lngBlockCount As Long 'the number of total whole block
Dim lngLastBlock As Integer 'the length of the last block
Dim lngBlockIndex As Long 'the index of each block
Dim ByteGet() As Byte '用于传送数据的二进制数组
Dim FileNum As Integer 'return the file number which the next file will use
Dim strFileName As Stringtemp_path = Space$(MAX_PATH)
length = GetTempPath(MAX_PATH, temp_path)
temp_path = Left$(temp_path, length)
temp_file = Space$(MAX_PATH)
GetTempFileName temp_path, "per", 0, temp_file
strFileName = Left$(temp_file, InStr(temp_file, Chr$(0)) - 1) MYrs.MoveFirst
MYrs.Move RecordPoint
Label1 = MYrs.AbsolutePosition
frmMain.Caption = MYrs.Fields("name") + Str(i)
FileNum = FreeFile()
Open strFileName For Binary As #FileNum
lngFileLength = MYrs.Fields("size")
lngBlockCount = lngFileLength \ lngBlockSize
lngLastBlock = lngFileLength Mod lngBlockSize
For lngBlockIndex = 1 To lngBlockCount
ByteGet() = MYrs.Fields("pic").GetChunk(lngBlockSize)
Put #FileNum, , ByteGet()
Next
If lngLastBlock > 0 Then
ReDim ByteGet(lngLastBlock)
ByteGet() = MYrs.Fields("pic").GetChunk(lngBlockSize)
Put #FileNum, , ByteGet()
End If
Picture1.Picture = LoadPicture(strFileName)
Close #FileNum
Kill strFileName
Err.Clear
End SubPrivate Sub AimFilePath(ByVal strPath As String)
Dim PathVal As String
PathVal = Dir(strPath)
If PathVal = Null Then MsgBox "null"
Do While PathVal <> ""
SaveInto (strPath + PathVal)
PathVal = Dir
Loop
End Sub