简单写个获取IPicture接口对象的示例
重点谈接口部份,省略内存图片数据编辑部份,直接将图片文件读入内存。
主要调用:
GlobalAlloc()分配内存
CreateStreamOnHGlobal()获取IStream接口
OleLoadPicture(IPicture)获取IPicture接口
**
** test.prg
**
DECLARE LONG CreateFile IN Kernel32 STRING@, LONG, LONG, LONG, LONG, LONG, LONG
DECLARE LONG GetFileSize IN Kernel32 LONG, LONG@
DECLARE LONG ReadFile IN Kernel32 LONG, LONG, LONG, LONG@, LONG
DECLARE LONG CloseHandle IN Kernel32 LONG
DECLARE LONG GlobalAlloc IN Kernel32 LONG, LONG
DECLARE LONG GlobalLock IN Kernel32 LONG
DECLARE LONG GlobalUnlock IN Kernel32 LONG
DECLARE LONG GlobalFree IN Kernel32 LONG
DECLARE LONG CreateStreamOnHGlobal IN Ole32 LONG, LONG, STRING@
DECLARE LONG OleLoadPicture IN OleAut32 LONG, LONG, LONG, STRING@, STRING@
LOCAL hFile
** HANDLE hFile=CreateFile(szImagePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)
hFile = CreateFile("C:\temp\test.bmp", 0x80000000, 1, 0, 3, 0x80, 0)
IF (hFIle == -1)
RETURN
ENDIF
LOCAL nHSize, nLSize, nFileSize
nHSize = 0
nLSize = GetFileSize(hFile, @nHSize)
nFileSize = nHSize * 0x100000000 + nLSize
LOCAL hImageMemory, pImageMemory
hImageMemory = GlobalAlloc(0x42, nFileSize) && GMEM_MOVEABLE | GMEM_ZEROINIT
pImageMemory = GlobalLock(hImageMemory)
LOCAL nReadSize
nReadSize = 0
ReadFile(hFile, pImageMemory, nFileSize, @nReadSize, 0)
GlobalUnlock(hImageMemory)
CloseHandle(hFile)
LOCAL pIStream
pIStream = REPLICATE(0h00, 4)
CreateStreamOnHGlobal(hImageMemory, 0, @pIStream)
*IID_IPicture is defined as 7BF80980-BF32-101A-8BBB-00AA00300CAB
LOCAL IID_IPicture, pIPicture
IID_IPicture = 0h8009F87B32BF1A108BBB00AA00300CAB
pIPicture = REPLICATE(0h00, 4)
OleLoadPicture(CTOBIN(pIStream,"4RS"), 0, 0, @IID_IPicture, @pIPicture)
oIPicture = SYS(3096, CTOBIN(pIPicture,"4RS"))
_screen.AddObject("Image1", "image")
_screen.Image1.width = 300
_screen.Image1.height = 200
_screen.Image1.PictureVal = oIPicture
_screen.Image1.Visible = .T.
MESSAGEBOX("结束......")
_screen.RemoveObject("Image1")
GlobalFree(hImageMemory)
CLEAR ALL