明明是出现在 Visual Basic 论坛的问题,怎么会是 C++ Builder 的呢?这个论坛太怪了。如果你用 ADO 的话,关键字:AppendChunk
解决方案 »
- 关于vb比较两个数大小的问题
- 窗体上有textbox(index0-9),和一个button,要求textbox(index2-8只允许数值输入,index0,1,9不作要求),当index0-9都不为空时。。。。
- vb中的DataReport 问题
- 菜鸟求助:VB中 DataGrid的排序和导出问题,求高手
- 下面代码出现错误:对象未定义或with块未设置,什么问题。
- 菜鸟提问~如何设置richtext颜色~??
- 写出代码了 谁能帮我画个流程图?(一共14行代码)
- 求救!关于数组的输值!
- 怎样通过datarpeort来控制只打印当天的记录
- 神啊,救救我
- 哪个表格支持右键操作
- 急!急!急!VB编的程序用了第三方控件,为什么在程序运行时总提示第三方控件的OCX版本不对??
如:数据库的链接、表名、字段等!!!
Function SavePictureDate() '(rstMain As DAO.Recordset) ', strFileName As String)
Dim FileHandle As String
Dim lngLogoSize As Long
Dim varLogo() As Byte
''rstMain.AddNew
''rstMain(0).Value = txtBH.Text
'FileHandle = FreeFile
On Error GoTo ErrLinePic
Open strFileName For Binary As #1 'FileHandle
lngLogoSize = FileLen(strFileName)
ReDim varLogo(lngLogoSize - 1)
Get #1, , varLogo() '数 组 名 加 ()可 以 代 表 数 组
Adodc1.Recordset("多媒体1").AppendChunk varLogo() 'rstMain("多媒体1").AppendChunk varLogo()
Close #1
'Adodc1.Recordset("多媒体N1") = Right(strFileName, 4)
Adodc1.Recordset("多媒体S1") = lngLogoSize
'rstMain.Update
ErrLinePic:
End FunctionFunction ShowPictureDate() '(rstMain As adodb.Recordset, gTempPath As String)
'显 示 图 片
Dim lngLogoSize As Long
Dim varLogo() As Byte
Dim strTempPath, strTempFileName As String
Dim lResult As Long
Dim FileHandle As Long
On Error GoTo ErrLinePicS
strTempPath = App.Path 'gTempPath '请 自 行 得 到 Temp路 径
strTempFileName = strTempPath & Adodc1.Recordset("多媒体N1") ' & rstMain(2) '存 为 一 临 时 文 件
FileHandle = 2 'FreeFile
Open strTempFileName For Output As #FileHandle
Close #FileHandle
Open strTempFileName For Binary As #FileHandle
lngLogoSize = Adodc1.Recordset("多媒体S1")
ReDim varLogo(lngLogoSize - 1)
varLogo() = Adodc1.Recordset("多媒体1").GetChunk(lngLogoSize)
Put #2, , varLogo
Close #2
Set Image1.Picture = LoadPicture(strTempFileName)
ErrLinePicS:
End Function
MODUAL模块:
Public bit() As Byte
Public txtdbname As String
Public Enum CBoolean
CFalse = 0
ctrue = 1
End Enum
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 TypeDeclare 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窗体引用:
写:
Open dbfilename For Binary As #1
ReDim bit(LOF(1)) As Byte
Get 1, 1, bit
Close 1
rs("pic").AppendChunk bit
读:
dim bit1 as byte
bit1 = rs("pic").GetChunk(rs("pic").ActualSize)
Picture1.Picture = PictureFromBits(bit1())