Click or drag to resize

DIBCreateFromPTR Function

X#
Convert an image file to a device independent bitmap (DIB).

Namespace:  VOGUIClasses
Assembly:  VOGUIClasses (in VOGUIClasses.dll) Version: 2.19
Syntax
 FUNCTION DIBCreateFromPTR(
	pbImage AS BYTE*,
	nSize AS LONG
) AS PTR
Request Example View Source

Parameters

pbImage
Type: Byte*
Pointer to the first byte of image data.
nSize
Type: Long
Size (number of bytes) of image data.

Return Value

Type: Void*
Pointer to DIB data which can be displayed; otherwise, NULL_PTR.
Remarks
DIBCreateFromPtr() converts an image file of type .JPG, .TIF, .BMP, .TGA, .PNG, .PCX, or .PCT into a device independent bitmap (.DIB file).
Examples
The following sample converts a file, test.jpg, and displays the DIB within a TopAppWindow:
X#
 1METHOD Start() CLASS App
 2LOCAL oWin
 3AS MyWindow
 4LOCAL hf
 5AS PTR
 6LOCAL nSize AS INT
 7LOCAL pDib
 8AS PTR
 9WCSetCoordinateSystem(WCWindowsCoordinates)
10InitializeCAPaint()
11hf := FOpen("test.jpg")
12IF hf != F_ERROR
13nSize := FSeek(hf, 0, FS_END)
14FSeek(hf, 0, FS_SET)
15pDib := MemAlloc(nSize)
16IF FRead3(hf, pDib, nSize) == nSize
17oWin := MyWindow{ SELF, pDib, nSize }
18oWin:Show(SHOWCENTERED)
19ENDIF
20FClose(hf)
21SELF:Exec()
22oWin:Axit()
23MemFree(pDib)
24ENDIF
25CLASS MyWindow INHERIT TopAppWindow
26PROTECT pBitMap  AS PTR
27PROTECT lBitMap  AS LOGIC
28CONSTRUCTOR(oParent, xFile, nSize)
29LOCAL pBmiH   AS _WINBITMAPINFO
30LOCAL nHeight  AS INT
31LOCAL nWidth
32AS INT
33LOCAL oPOint
34AS POINT
35LOCAL hWnd
36AS PTR
37LOCAL cx
38AS INT
39LOCAL cy
40AS INT
41LOCAL cr    IS _WINRECT
42LOCAL wr    IS _WINRECT
43SUPER:Init(oParent)
44SELF:QuitOnClose := TRUE
45IF IsPtr(xFile) .AND. IsNumeric(nSize)
46SELF:pBitMap := DIBCreateFromPtr(xFile, nSize)
47ENDIF
48IF pBitMap = NULL_PTR
49MessageBox(0, "Error reading image", "ERROR ", MB_ICONSTOP)
50ELSE
51SELF:lBitmap := .T.
52oPoint := SELF:Origin
53pBmiH  := DIBGetInfo(pBitMap)
54nHeight := pBmiH.bmiHeader.biHeight
55nWidth := pBmiH.bmiHeader.biWidth
56hWnd  := SELF:Handle()
57GetWindowRect(hWnd, @wr)
58GetClientRect(hWnd, @cr)
59cx := wr.right - wr.left - cr.right
60cy := wr.bottom - wr.top - cr.bottom
61SELF:Size  := DIMension{nWidth + cx, nHeight + cy}
62SELF:Origin := oPoint
63ENDIF
64RETURN SELF
65
66METHOD Expose(oExposeEvent)
67SUPER:Expose(oExposeEvent)
68IF SELF:lBitMap
69DIBShow( SELF:pBitMap, NULL_PTR )
70ENDIF
71DESTRUCTOR()    CLASS MyWindow
72DIBDelete(SELF:pBitmap)
73END CLASS
See Also