读出图片的代码!r("zp")为bin型 Dim bit1() As Byte
On Error GoTo Err1:
bit1 = r("zp").GetChunk(r("zp").ActualSize)
'然后将字节数组的内容拼装成文件即可
Open App.Path & "\temp.jpg" For Binary As #1
Put 1, 1, bit1
Close 1
Image1.Stretch = False
Image1 = LoadPicture(App.Path & "\temp.jpg")
Image1.Tag = App.Path & "\temp.jpg"
'5655,120
zz = Image1.Height / Image1.Width
If Image1.Height > Picture1.Height Or Image1.Width > Picture1.Width Then
If Image1.Height > Image1.Width Then
'高大于宽
Image1.Height = Picture1.Height
Image1.Width = Image1.Height / zz
Image1.Left = (Picture1.Width - Image1.Width) / 2
Image1.Top = 0
Else
Image1.Width = Picture1.Width
Image1.Height = Image1.Width * zz
Image1.Top = (Picture1.Height - Image1.Height) / 2
Image1.Left = 0
End If
End If
Image1.Stretch = True
End If
r.Close
On Error GoTo 0
Exit Sub
Err1:
Image1.Tag = ""
On Error GoTo Err1:
bit1 = r("zp").GetChunk(r("zp").ActualSize)
'然后将字节数组的内容拼装成文件即可
Open App.Path & "\temp.jpg" For Binary As #1
Put 1, 1, bit1
Close 1
Image1.Stretch = False
Image1 = LoadPicture(App.Path & "\temp.jpg")
Image1.Tag = App.Path & "\temp.jpg"
'5655,120
zz = Image1.Height / Image1.Width
If Image1.Height > Picture1.Height Or Image1.Width > Picture1.Width Then
If Image1.Height > Image1.Width Then
'高大于宽
Image1.Height = Picture1.Height
Image1.Width = Image1.Height / zz
Image1.Left = (Picture1.Width - Image1.Width) / 2
Image1.Top = 0
Else
Image1.Width = Picture1.Width
Image1.Height = Image1.Width * zz
Image1.Top = (Picture1.Height - Image1.Height) / 2
Image1.Left = 0
End If
End If
Image1.Stretch = True
End If
r.Close
On Error GoTo 0
Exit Sub
Err1:
Image1.Tag = ""
ReDim bit(LOF(1)) As Byte
Get 1, 1, bit
Close 1
r.Open "select * from byzl where kh='" & Trim(Txtkh) & "'", Cn, adOpenKeyset, adLockOptimistic
r("zp").AppendChunk bit
r.Update
r.Close
End If
假如不指定temp.jpg文件,而是动态的选择怎么办
Declare Function CreateStreamOnHGlobal Lib "ole32" _
(ByVal hGlobal As Long, _
ByVal fDeleteOnRelease As CBoolean, _
ppstm As Any) As LongDeclare Function OleLoadPicture Lib "olepro32" _
(pStream As Any, _
ByVal lSize As Long, _
ByVal fRunmode As CBoolean, _
riid As GUID, _
ppvObj As Any) As LongPublic Type GUID
dwData1 As Long
wData2 As Integer
wData3 As Integer
abData4(7) As Byte
End TypePublic Enum CBoolean
CFalse = 0
CTrue = 1
End Enum
Declare Function CLSIDFromString Lib "ole32" (ByVal lpsz As Any, pclsid As GUID) As Long
Public Const sIID_IPicture = "{7BF80980-BF32-101A-8BBB-00AA00300CAB}"
Public Const GMEM_MOVEABLE = &H2
Public Const S_OK = 0
Declare Function GlobalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal dwBytes As Long) As Long
Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)'_______________________________________________________________
Public Function PictureFromBits(abPic() As Byte) As IPicture
Dim nLow As Long
Dim cbMem As Long
Dim hMem As Long
Dim lpMem As Long
Dim IID_IPicture As GUID
Dim istm As stdole.IUnknown
Dim ipic As IPicture On Error GoTo Out
nLow = LBound(abPic)
On Error GoTo 0
cbMem = (UBound(abPic) - nLow) + 1
hMem = GlobalAlloc(GMEM_MOVEABLE, cbMem)
If hMem Then
lpMem = GlobalLock(hMem)
If lpMem Then
MoveMemory ByVal lpMem, abPic(nLow), cbMem
Call GlobalUnlock(hMem)
If (CreateStreamOnHGlobal(hMem, CTrue, istm) = S_OK) Then
If (CLSIDFromString(StrPtr(sIID_IPicture), IID_IPicture) = S_OK) Then
Call OleLoadPicture(ByVal ObjPtr(istm), cbMem, CFalse, IID_IPicture, PictureFromBits)
End If
End If
End If
End If
Out:
End Function
'Form
Private Sub Command1_Click()
Dim TRst As ADODB.Recordset
Dim SqlStr As String
Dim Bit1() As Byte
Dim Bit1Leg As Long
Set TRst = New ADODB.Recordset
SqlStr = "Select * from TablePic"
TRst.Open SqlStr, DB, adOpenStatic, adLockReadOnly
If TRst.RecordCount > 0 Then
TRst.MoveFirst
Bit1Leg = TRst.Fields(2).ActualSize
Bit1 = TRst.Fields(2).GetChunk(Bit1Leg)
Picture1.Picture = PictureFromBits(Bit1())
End Sub
Open App.Path & "\temp.jpg" For Binary As #1
假如不指定temp.jpg文件,而是动态的选择怎么办 回答:就改呀! 这还要说吗? 用通用对话框呀!