以下是引用eepcvfp在2018-2-5 20:35:26的发言:
谢谢 吹版!
您的代码示范了获取IPicture接口对象,但是从存盘文件创建的,怎么把用GDI+绘制的图像生成IPicture接口对象呢?
我先研究一下您的代码。
再次感谢!!!
谢谢 吹版!
您的代码示范了获取IPicture接口对象,但是从存盘文件创建的,怎么把用GDI+绘制的图像生成IPicture接口对象呢?
我先研究一下您的代码。
再次感谢!!!
示例是忽略内存编辑图片过程,直接从文件读入内存。
再写个内存编辑图片示例参考:
为简化算法,用 32位100*100 BMP图片格式,这样可以不用考虑字节对齐问题。
图片效果:黑底和两对角红线。
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 hImageMemory, pImageMemory
hImageMemory = GlobalAlloc(0x42, 40054) && Size: 54+100*100*4 = 40054
pImageMemory = GlobalLock(hImageMemory)
_CreateBitmap(pImageMemory)
GlobalUnlock(hImageMemory)
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.top = 10
_screen.Image1.left = 10
_screen.Image1.width = 100
_screen.Image1.height = 100
_screen.Image1.PictureVal = oIPicture
_screen.Image1.Visible = .T.
MESSAGEBOX("结束......")
_screen.RemoveObject("Image1")
GlobalFree(hImageMemory)
CLEAR ALL
FUNCTION _CreateBitmap(pBuf)
LOCAL BITMAPINFO
BITMAPINFO = "BM"+; && Type: BM
BINTOC(40054, "4RS")+; && Size: 54+100*100*4 = 40054
REPLICATE(0h00, 4)+; && Reserved1: 0, Reserved2: 0
BINTOC(54, "4RS")+; && OffBits: 54
BINTOC(40, "4RS")+; && Size: 40
BINTOC(100, "4RS")+; && Width: 100
BINTOC(100, "4RS")+; && Height: 100
BINTOC(1, "2RS")+; && Planes: 1
BINTOC(32, "2RS")+; && BitCount: 32
REPLICATE(0h00, 4)+; && Compression: 0
BINTOC(40000, "4RS")+; && SizeImage: 100*100*4=40000
BINTOC(18893, "4RS")+; && XPelsPerMeter: 18893
BINTOC(18893, "4RS")+; && YPelsPerMeter: 18893
REPLICATE(0h00, 8) && ClrUsed: 0, ClrImportant: 0
SYS(2600, pBuf, 54, BITMAPINFO)
pBuf = pBuf + 54
FOR i=0 TO 99
SYS(2600, pBuf+i*404, 4, BINTOC(0xFF0000,"4RS"))
SYS(2600, pBuf+i*396, 4, BINTOC(0xFF0000,"4RS"))
ENDFOR
ENDFUNC