标题:用GDI+绘制的图像生成StdPicture对象
只看楼主
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
以下是引用eepcvfp在2018-2-5 20:35:26的发言:

谢谢 吹版!

您的代码示范了获取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
2018-02-05 20:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-484603-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.126217 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved