点击或拖拽改变大小

Functions.DIBCreateFromPTR 方法

X#
将图像文件转换为设备无关位图 (DIB)。

命名空间:  VOGUIClasses
程序集:  VOGUIClasses (在 VOGUIClasses.dll 中) 版本:2.22 GA
语法
 FUNCTION DIBCreateFromPTR(
	pbImage AS BYTE*,
	nSize AS LONG
) AS PTR
查看代码

参数

pbImage
类型:Byte*
指向图像数据的第一个字节的指针。
nSize
类型:Int32
图像数据的大小 (字节数)。

返回值

类型:Void*
指向 DIB 数据的指针,否则 NULL_PTR。
备注
DIBCreateFromPtr() 将图像文件 (JPG, TIF, BMP, TGA, PNG, PCX, PCT) 转换为设备无关位图 (DIB)。
示例
以下示例将文件 test.jpg 转换并显示在一个 TopAppWindow 中:
X#
 1METHOD Start() CLASS App
 2LOCAL oWin AS MyWindow
 3LOCAL hf AS PTR
 4LOCAL nSize AS INT
 5LOCAL pDib AS PTR
 6
 7WCSetCoordinateSystem(WCWindowsCoordinates)
 8InitializeCAPaint()
 9
10hf := FOpen("test.jpg")
11
12IF hf != F_ERROR
13    nSize := FSeek(hf, 0, FS_END)
14    FSeek(hf, 0, FS_SET)
15    pDib := MemAlloc(nSize)
16
17    IF FRead3(hf, pDib, nSize) == nSize
18        oWin := MyWindow{ SELF, pDib, nSize }
19        oWin:Show(SHOWCENTERED)
20    ENDIF
21
22    FClose(hf)
23    SELF:Exec()
24    oWin:Axit()
25    MemFree(pDib)
26ENDIF
27
28CLASS MyWindow INHERIT TopAppWindow
29    PROTECT pBitMap AS PTR
30    PROTECT lBitMap AS LOGIC
31
32    CONSTRUCTOR(oParent, xFile, nSize)
33        LOCAL pBmiH AS _WINBITMAPINFO
34        LOCAL nHeight AS INT
35        LOCAL nWidth AS INT
36        LOCAL oPOint AS POINT
37        LOCAL hWnd AS PTR
38        LOCAL cx AS INT
39        LOCAL cy AS INT
40        LOCAL cr IS _WINRECT
41        LOCAL wr IS _WINRECT
42
43        SUPER:Init(oParent)
44        SELF:QuitOnClose := TRUE
45
46        IF IsPtr(xFile) .AND. IsNumeric(nSize)
47            SELF:pBitMap := DIBCreateFromPtr(xFile, nSize)
48        ENDIF
49
50        IF pBitMap = NULL_PTR
51            MessageBox(0, "Error reading image", "ERROR ", MB_ICONSTOP)
52        ELSE
53            SELF:lBitmap := .T.
54            oPoint      := SELF:Origin
55            pBmiH       := DIBGetInfo(pBitMap)
56            nHeight     := pBmiH.bmiHeader.biHeight
57            nWidth      := pBmiH.bmiHeader.biWidth
58            hWnd        := SELF:Handle()
59            GetWindowRect(hWnd, @wr)
60            GetClientRect(hWnd, @cr)
61            cx          := wr.right - wr.left - cr.right
62            cy          := wr.bottom - wr.top - cr.bottom
63            SELF:Size   := DIMension{nWidth + cx, nHeight + cy}
64            SELF:Origin := oPoint
65        ENDIF
66
67        RETURN SELF
68
69    METHOD Expose(oExposeEvent)
70        SUPER:Expose(oExposeEvent)
71
72        IF SELF:lBitMap
73            DIBShow( SELF:pBitMap, NULL_PTR )
74        ENDIF
75
76    DESTRUCTOR() CLASS MyWindow
77        DIBDelete(SELF:pBitmap)
78END CLASS
参见