Dim strFree As String Dim lngFileLen As Long Dim bytFile() As Byte Dim lngBlocks As Long Dim lngLeft As Long Dim lngNum As Long======= mvarphoto是图片的路径 If mvarPhoto <> "" Then strFree = FreeFile Open mvarPhoto For Binary Access Read As strFree lngFileLen = LOF(strFree) If lngFileLen > 0 Then lngBlocks = lngFileLen / BLOCK_SIZE lngLeft = lngFileLen Mod BLOCK_SIZE ReDim bytFile(BLOCK_SIZE) For lngNum = 1 To lngBlocks Get strFree, , bytFile() recFind("photo").AppendChunk bytFile() Next lngNum If lngLeft > 0 Then ReDim bytFile(lngLeft) Get strFree, , bytFile() recFind("photo").AppendChunk bytFile() End If End If End If
这个函数不行啊 Public Function ReadPic(ByVal fldPic As adodb.Field, picShow As PictureBox) As Boolean Dim strTemp As String Dim strFree As String Dim lngFldSize As Long Dim bytFile() As Byte Dim lngBlocks As Long Dim lngLeft As Long Dim lngNum As Long Dim BLOCK_SIZE As Integer BLOCK_SIZE = 10000<--这样行么On Error GoTo ErrHandler strTemp = App.Path & "\temppic.tmp" strFree = FreeFile Open strTemp For Binary Access Write As strFree lngFldSize = fldPic.ActualSize If lngFldSize = 0 Then Exit Function lngBlocks = lngFldSize \ BLOCK_SIZE lngLeft = lngFldSize Mod BLOCK_SIZE For lngNum = 1 To lngBlocks bytFile() = fldPic.GetChunk(BLOCK_SIZE) Put strFree, , bytFile() Next lngNum
If lngLeft > 0 Then bytFile() = fldPic.GetChunk(lngLeft) Put strFree, , bytFile() End If Close strFree picShow.Picture = LoadPicture(strTemp)<---到这里就跳到Err了 ReadPic = True Exit Function ErrHandler: MsgBox "ERR" ReadPic = False End Function
Dim BLOCK_SIZE As Integer BLOCK_SIZE = 10000<--这样行么这两句不要!
去掉了 但是还是一样问题 Close strFree picShow.Picture = LoadPicture(strTemp)<---到这里就跳到Err了 ReadPic = True Exit Function ErrHandler: MsgBox "ERR" ReadPic = False End Function
Dim lngFileLen As Long
Dim bytFile() As Byte
Dim lngBlocks As Long
Dim lngLeft As Long
Dim lngNum As Long=======
mvarphoto是图片的路径
If mvarPhoto <> "" Then
strFree = FreeFile
Open mvarPhoto For Binary Access Read As strFree
lngFileLen = LOF(strFree)
If lngFileLen > 0 Then
lngBlocks = lngFileLen / BLOCK_SIZE
lngLeft = lngFileLen Mod BLOCK_SIZE
ReDim bytFile(BLOCK_SIZE)
For lngNum = 1 To lngBlocks
Get strFree, , bytFile()
recFind("photo").AppendChunk bytFile()
Next lngNum
If lngLeft > 0 Then
ReDim bytFile(lngLeft)
Get strFree, , bytFile()
recFind("photo").AppendChunk bytFile()
End If
End If
End If
Public Function ReadPic(ByVal fldPic As adodb.Field, picShow As PictureBox) As Boolean
Dim strTemp As String
Dim strFree As String
Dim lngFldSize As Long
Dim bytFile() As Byte
Dim lngBlocks As Long
Dim lngLeft As Long
Dim lngNum As Long Dim BLOCK_SIZE As Integer
BLOCK_SIZE = 10000<--这样行么On Error GoTo ErrHandler
strTemp = App.Path & "\temppic.tmp"
strFree = FreeFile
Open strTemp For Binary Access Write As strFree
lngFldSize = fldPic.ActualSize
If lngFldSize = 0 Then Exit Function
lngBlocks = lngFldSize \ BLOCK_SIZE
lngLeft = lngFldSize Mod BLOCK_SIZE
For lngNum = 1 To lngBlocks
bytFile() = fldPic.GetChunk(BLOCK_SIZE)
Put strFree, , bytFile()
Next lngNum
If lngLeft > 0 Then
bytFile() = fldPic.GetChunk(lngLeft)
Put strFree, , bytFile()
End If
Close strFree
picShow.Picture = LoadPicture(strTemp)<---到这里就跳到Err了
ReadPic = True
Exit Function
ErrHandler:
MsgBox "ERR"
ReadPic = False
End Function
这是一个全局常量
BLOCK_SIZE = 10000<--这样行么这两句不要!
但是还是一样问题
Close strFree
picShow.Picture = LoadPicture(strTemp)<---到这里就跳到Err了
ReadPic = True
Exit Function
ErrHandler:
MsgBox "ERR"
ReadPic = False
End Function
如果是access ,字段类型是ole对象?
你的数据库的“图片“字段有图片数据吗?
"C:\Documents and Settings\huntty1\My Documents\huang\temppic.tmp"
temp文件也是我要的图片文件
但是为什么不显示那?
是不是文件格式有要求?
还是picturebox里面还有什么属性没有设置?
应该支持得把
但是为什么就是不显示那?
C:\Documents and Settings\huntty1\My Documents\huang\temppic.tmp
这个文件我用acdsee打开就是我数据库里的文件啊