| 发表于:2007-03-19 08:33:345楼 得分:20 |
public declare function createstreamonhglobal lib "ole32 " (byval hglobal as long, byval fdeleteonrelease as long, ppstm as any) as long public declare function oleloadpicture lib "olepro32 " (pstream as any, byval lsize as long, byval frunmode as long, riid as any, ppvobj as any) as long public declare function clsidfromstring lib "ole32 " (byval lpsz as any, pclsid as any) as long public declare function globalalloc lib "kernel32 " (byval uflags as long, byval dwbytes as long) as long public declare function globallock lib "kernel32 " (byval hmem as long) as long public declare function globalunlock lib "kernel32 " (byval hmem as long) as long public declare function globalfree lib "kernel32 " (byval hmem as long) as long public declare sub copymemory lib "kernel32 " alias "rtlmovememory " (destination as any, source as any, byval length as long) '************************************************************** ' 参数说明: ' ' bimagedata(): 保存图像信息的字节数组。 ' ' 返回值: ' ' 返回转换后的 ipictredisp 对象。 '************************************************************** public function getpicturefrombytestream(bimagedata() as byte) as ipicture dim lngbytecount as long dim hmem as long dim lpmem as long dim iid_ipicture(15) dim istream as stdole.iunknown on error goto err_init lngbytecount = ubound(bimagedata) + 1 ' 计算数组大小 hmem = globalalloc(&h2 or gmem_zeroinit, lngbytecount) ' 按数组大小分配一块内存空间 if hmem <> 0 then ' ' 若分配内存成功 lpmem = globallock(hmem) ' 锁定内存, 返回第一块的指针 if lpmem <> 0 then copymemory byval lpmem, bimagedata(0), lngbytecount call globalunlock(hmem) if createstreamonhglobal(hmem, 1, istream) = 0 then if clsidfromstring(strptr( "{7bf80980-bf32-101a-8bbb-00aa00300cab} "), iid_ipicture(0)) = 0 then call oleloadpicture(byval objptr(istream), lngbytecount, 0, iid_ipicture(0), getpicturefrombytestream) end if end if end if end if globalfree hmem exit function err_init: msgbox err.number & " - " & err.description end function 把图像数据存入字节数组,按如下调用即可: set picture1.picture=getpicturefrombytestream(bytdata()) | | |
|