Jump to content

How to get Width and Height of a GDI+ graphic object?


Gianni
 Share

Recommended Posts

Hi

how do I know the width and height of a GDI+ graphic object previously created with _GDIPlus_GraphicsCreateFromHWND()?

of course I will not get the size using WinGetClientSize(), I would getting dimensions directly from $hGraphicSurface

#include <GDIPlus.au3>

$hWinSurface = GUICreate("Drawing paper") ; Create a GUI window
GUISetState(@SW_SHOW)

$hGraphicSurface = _GDIPlus_GraphicsCreateFromHWND($hWinSurface) ; Create a Graphics object from a window handle

$iGraphicWidth = '?' ; <--- how to get Width of the $hGraphicSurface ???
$iGraphicHeight = '?' ; <-- how to get Height of the $hGraphicSurface ???

MsgBox(0, 'Sizes:', 'Width: ' & $iGraphicWidth & ' pixel' & @CRLF & 'Height: ' & $iGraphicHeight & 'pixel')

; .......

Thanks

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

I don't know if GDI(+) has some funtion for that (I'm not used to use GDI(+)). but you can do something like this:

 

#include <GDIPlus.au3>

_GDIPlus_Startup()

Local $hWinSurface = GUICreate("Drawing paper") ; Create a GUI window
GUISetState(@SW_SHOW)

Local $hGraphicSurface = _GDIPlus_GraphicsCreateFromHWND($hWinSurface)

Local $hDC = _GDIPlus_GraphicsGetDC($hGraphicSurface)

Local $hWnd = _WinAPI_WindowFromDC($hDC)


Local $tRECT=0

$tRECT = _WinAPI_GetClientRect($hWnd)
MsgBox($MB_SYSTEMMODAL, "Rect", _
        "Left..: " & DllStructGetData($tRECT, "Left") & @CRLF & _
        "Right.: " & DllStructGetData($tRECT, "Right") & @CRLF & _
        "Top...: " & DllStructGetData($tRECT, "Top") & @CRLF & _
        "Bottom: " & DllStructGetData($tRECT, "Bottom"))

 _GDIPlus_GraphicsDispose($hGraphicSurface)
_GDIPlus_Shutdown()

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

 I found another way looking the graphic's memory.

#include <GDIPlus.au3>



_GDIPlus_Startup()

Local $hWinSurface = GUICreate("Drawing paper",500,400) ; Create a GUI window
GUISetState(@SW_SHOW)


Local $hGraphicSurface = _GDIPlus_GraphicsCreateFromHWND($hWinSurface)

Local $tGraphic=DllStructCreate("long width;long height",$hGraphicSurface+24)
MsgBox(0,"","width: " & $tGraphic.width & @CRLF &  "height: " & $tGraphic.height)

_GDIPlus_GraphicsDispose($hGraphicSurface)

_GDIPlus_Shutdown()

Saludos

Link to comment
Share on other sites

Thanks a lot Danyfirex :)
interesting ways...
I prefer your second way because it doesn't need that "roundtrip" to recover back the original window's handle.
Was wondering if it exists a direct GDI+ way to get that infos...

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

27 minutes ago, Danyfirex said:

 I found another way looking the graphic's memory.

#include <GDIPlus.au3>



_GDIPlus_Startup()

Local $hWinSurface = GUICreate("Drawing paper",500,400) ; Create a GUI window
GUISetState(@SW_SHOW)


Local $hGraphicSurface = _GDIPlus_GraphicsCreateFromHWND($hWinSurface)

Local $tGraphic=DllStructCreate("long width;long height",$hGraphicSurface+24)
MsgBox(0,"","width: " & $tGraphic.width & @CRLF &  "height: " & $tGraphic.height)

_GDIPlus_GraphicsDispose($hGraphicSurface)

_GDIPlus_Shutdown()

Saludos

.... very nice,

one question please, where do you get that infos about the graphic's memory? (width and height at offset 24 for example ?)

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

I was lucky lol. I thought, that funtions return a graphic object(a pointer :think: memory :idea:). that pointer(memory area) should have some information for other funtions. I saw  some few memory bytes and notice that there are my values (width and height).  :dance:

 

Saludos

Link to comment
Share on other sites

Hi UEZ,

...thanks for coming to see me here... :P
In short, the purpose to get the dimension of the graphic object is because I'm "printing" dot matrix chars on the graphic object, and I have to wrap around to next line when I reach the right border. So I need to know the dimensions of the graphic object.

Edit: I need to get dimensions in that way (directly from the graphic object) so that if I use different graphics objects, I can pass only his Handle to a function, and the dimension can be obtained directly from the handle of the graphic object instead of having to take track of the dimensions of any graphic used.

Of course, I'm just playing "wild" with GDI+ for experimenting, so maybe I'm doing wrong steps.
Anyway, here is what I'm playing with:
While I was browsing around the web, I've seen this page: http://www.rinkydinkelectronics.com/r_fonts.php and I was curious to try to visualize those dot matrix fonts on a window with GDI+ so I wrote this draft and in some way it works... (even if this listing is a shit I'm proud anyway :D).
To be able to test it is necessary first download at least one of the DotMatrix fonts from the above page. The script will allow you to load the downloaded files from disk and will print using that dot matrix.

I'm using the code provided by Danyfirex in lines from 70 to 75.

#include <GDIPlus.au3>
#include <String.au3>

_GDIPlus_Startup()

Global Const $aNibbles[16][2] = [ _
        ["0000", "0"], _
        ["0001", "1"], _
        ["0010", "2"], _
        ["0011", "3"], _
        ["0100", "4"], _
        ["0101", "5"], _
        ["0110", "6"], _
        ["0111", "7"], _
        ["1000", "8"], _
        ["1001", "9"], _
        ["1010", "A"], _
        ["1011", "B"], _
        ["1100", "C"], _
        ["1101", "D"], _
        ["1110", "E"], _
        ["1111", "F"]]
;
Global Const $aDOS_color[16] = [ _
        0xFF000000, _ ; 0x0 = 00 = Black
        0XFF000080, _ ; 0x1 = 01 = Blue
        0XFF008000, _ ; 0x2 = 02 = Green
        0XFF008080, _ ; 0x3 = 03 = Aqua
        0XFF800000, _ ; 0x4 = 04 = Red
        0XFF800080, _ ; 0x5 = 05 = Purple
        0XFF808000, _ ; 0x6 = 06 = Yellow
        0XFFC0C0C0, _ ; 0x7 = 07 = White
        0XFF808080, _ ; 0x8 = 08 = Gray
        0XFF0000FF, _ ; 0x9 = 09 = Light Blue
        0XFF00FF00, _ ; 0xA = 10 = Light Green
        0XFF00FFFF, _ ; 0xB = 11 = Light Aqua
        0XFFFF0000, _ ; 0xC = 12 = Light Red
        0XFFFF00FF, _ ; 0xD = 13 = Light Purple
        0XFFFFFF00, _ ; 0xE = 14 = Light Yellow
        0xFFFFFFFF];  ; 0xF = 15 = Bright White
;
Global $iPixSide = 1, _ ;   side of char's pixels
        $iVtab = 0, _ ; Vertical position of cursor
        $iHtab = 0, _ ; Horizontal position of cursor
        $iBG_DefaultColor = 0, _ ; Default Background color 0 = Black
        $iFG_DefaultColor = 10, _ ; Default Foreground color 7 = White
        $ahColors[2] = [ _ ; Array of brush handles
        _GDIPlus_BrushCreateSolid($aDOS_color[$iBG_DefaultColor]), _ ; default background for chars (Format AARRGGBB)
        _GDIPlus_BrushCreateSolid($aDOS_color[$iFG_DefaultColor])], _ ;   default foreground for chars.
        $iWidth, _ ; Width in bit of char
        $iHeight ;   height in bit of char

HotKeySet("{ESC}", "_Terminate")

; ------------------
Local $iWinWidth = 500
Local $iWinHeight = 400
Local $hScreen = GUICreate("", $iWinWidth, $iWinHeight, 10, 10)
Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hScreen)
GUISetState(@SW_SHOW, $hScreen)

Local $aFont, $tGraphic

While 1
    $aFont = _LoadFont()
    If IsArray($aFont) Then
        For $i = 0 To UBound($aFont) - 1 ; just for test, it prints all chars contained in the font
            _CharGen($hGraphic, $aFont[$i]); print a bitmapped char on the graphic object
            ; update cursor position
            $tGraphic = DllStructCreate("long width;long height", $hGraphic + 24) ; thanks to Danyfirex!
            $iHtab += ($iWidth * $iPixSide)
            If $iHtab > $tGraphic.width - ($iWidth * $iPixSide) Then
                $iVtab += ($iHeight * $iPixSide)
                $iHtab = 0
                If $iVtab > $tGraphic.height - ($iHeight * $iPixSide) Then $iVtab = 0
            EndIf
        Next
    EndIf
    _CharColor(Random(1, 15, 1)) ; random foreground color
WEnd

_Terminate()

Func _CharGen($hGraphic, $vBits, $iBase = 8)
    If IsArray($vBits) Then
        ; if argument is an array then third parameter is ignored since it can be inferred from array dim and array content itself
        For $iRow = UBound($vBits) - 1 To 0 Step -1 ; UBound of array is the number of rows
            For $iBit = StringLen($vBits[$iRow]) To 1 Step -1;StringLen of array's content is the number of horizontal pixels
                _GDIPlus_GraphicsFillRect($hGraphic, _ ; it draws a single pixel at a time
                        $iHtab + $iPixSide * $iBit, _ ; Horizontal pixel position within the matrix
                        $iVtab + $iPixSide * $iRow, _ ; Vertical pixel position within the matrix
                        $iPixSide, $iPixSide, _ ; pixel is a square
                        $ahColors[StringMid($vBits[$iRow], $iBit, 1)]) ; bit 0 = background; bit 1 = foreground
            Next ; next horizontal pixel
        Next ; next row
    Else
        For $iBit = StringLen($vBits) - 1 To 0 Step -1 ; get all bits one by one
            _GDIPlus_GraphicsFillRect($hGraphic, _ ; it draws a single pixel at a time
                    $iHtab + $iPixSide * Mod($iBit, $iBase), _ ;  Horizontal pixel position within the matrix
                    $iVtab + $iPixSide * Int($iBit / $iBase), _ ; Vertical pixel position within the matrix
                    $iPixSide, $iPixSide, _ ; pixel is a square
                    $ahColors[StringMid($vBits, $iBit + 1, 1)])
        Next
    EndIf
EndFunc   ;==>_CharGen

; ------------------------------------------------------------
; set Background and foreground colors for chars
; for DOS style pass 0x00 to 0xFF as single argument
; for custom colors use 0xAARRGGBB format for both arguments
; for reset to default colors just call func without arguments
; ------------------------------------------------------------
Func _CharColor($vBackGr = "", $vForeGr = "")
    If $vBackGr == "" And $vForeGr == "" Then ; set default
        _GDIPlus_BrushSetSolidColor($ahColors[0], $aDOS_color[$iBG_DefaultColor]) ; background
        _GDIPlus_BrushSetSolidColor($ahColors[1], $aDOS_color[$iFG_DefaultColor]) ; foreground
    ElseIf $vBackGr < 256 And $vForeGr = "" Then ; set as in DOS (use 0xNN N_=backgroung _N=foreground)
        $vForeGr = Dec(Hex($vBackGr, 1))
        $vBackGr = Dec(StringLeft(String(Hex($vBackGr, 2)), 1))
        _GDIPlus_BrushSetSolidColor($ahColors[0], $aDOS_color[$vBackGr]) ; background
        _GDIPlus_BrushSetSolidColor($ahColors[1], $aDOS_color[$vForeGr]) ; foreground
    Else ; set custom colors
        _GDIPlus_BrushSetSolidColor($ahColors[0], $vBackGr) ; background
        _GDIPlus_BrushSetSolidColor($ahColors[1], $vForeGr) ; foreground
    EndIf
EndFunc   ;==>_CharColor

Func _LoadFont()
    ; Display an open dialog to select a list of file(s).
    Local $sFile = FileOpenDialog("Select a font file?", "", "All (*.c)", $FD_FILEMUSTEXIST)
    ;
    ; Read the file.c
    Local $hFile = FileOpen($sFile)
    Local $sFont = FileRead($hFile)
    FileClose($hFile)
    ;
    $aBytes = _StringBetween($sFont, "0x", ",") ; extract only binary bytes
    ;
    $iWidth = Dec($aBytes[0]) ; Width in bit of each single char
    $iHeight = Dec($aBytes[1]) ; height
    Local $iWhatis = Dec($aBytes[2]) ; ?
    Local $iChars = Dec($aBytes[3]) ; nr of chars in this font

    Local $iBytesPerChar = ($iWidth * $iHeight) / 8

    Local $aFontMatrix[$iChars]
    Local $aTemp[$iHeight]
    Local $iNdx0 = 0, $iNdx1 = 0
    ;
    ; Transform Hex bytes to binary digits
    For $i = 4 To UBound($aBytes) - 1
        $aTemp[$iNdx1] &= _TextToBinaryString($aBytes[$i])
        If StringLen($aTemp[$iNdx1]) = $iWidth Then
            $iNdx1 += 1
            If $iNdx1 < $iHeight Then
                $aTemp[$iNdx1] = ""
            Else
                $aFontMatrix[$iNdx0] = $aTemp
                $iNdx0 += 1
                $iNdx1 = 0
                $aTemp[$iNdx1] = ""
            EndIf
        EndIf
    Next
    Return $aFontMatrix
EndFunc   ;==>_LoadFont

Func _TextToBinaryString($sHexText)
    Local $sBits = ""
    For $i = 1 To StringLen($sHexText)
        $sBits &= $aNibbles[Dec(StringMid($sHexText, $i, 1))][0]
    Next
    Return $sBits
EndFunc   ;==>_TextToBinaryString

Func _Terminate()
    If WinActive($hScreen) Then
        ; Clean up resources
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_BrushDispose($ahColors[0])
        _GDIPlus_BrushDispose($ahColors[1])
        _GDIPlus_Shutdown()
        MsgBox(0, "Debug", "Bye bye", 1)
        Exit
    EndIf
EndFunc   ;==>_Terminate

 

Edited by Chimp
added notes

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Local $iWinWidth = 500
Local $iWinHeight = 400
Local $hScreen = GUICreate("", $iWinWidth, $iWinHeight, 10, 10)
Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hScreen)

You are creating a graphic handle using a GUI. That means that the dimension of the graphic handle is the same as the GUI. If you know the GUI size than you know automatically also the size of the graphic handle.

$tGraphic.width  = $iWinWidth

$tGraphic.height = $iWinHeight

Further I would suggest to draw a bitmap rather than a graphic handle to be able to save the result easily.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

@UEZ Thank you for your advise,
Yes, you are right about $iWinWidth and $iWinHeight, but (as I asked in first post) that's what I would avoid to do, having to keeping track of the graphic object dimensions within variables or having to refer to its "parent" window. Instead I would get dimensions directly from the Graphic object itself, in a way as is done for getting properties in OO (as the solution proposed by Danyfirex). Or if only were available functions of the kind "_GDIPlus_GraphicsGetWidth"...

about the  using a bitmap rather than a graphic handle, I don't even exactly know how to do that, and what are the difference between the two ways. ...What should I use instead of _GDIPlus_GraphicsCreateFromHWND() ?

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

19 minutes ago, Chimp said:

about the  using a bitmap rather than a graphic handle, I don't even exactly know how to do that, and what are the difference between the two ways. ...What should I use instead of _GDIPlus_GraphicsCreateFromHWND() ?

A graphic handle is something like a canvas whereas a bitmap is like a picture which you are putting on the canvas. A graphic handle is a device only whereas a bitmap is a structe which held the information in the memory.

#include <GDIPlus.au3>
#include <String.au3>

_GDIPlus_Startup()

Global Const $aNibbles[16][2] = [ _
        ["0000", "0"], _
        ["0001", "1"], _
        ["0010", "2"], _
        ["0011", "3"], _
        ["0100", "4"], _
        ["0101", "5"], _
        ["0110", "6"], _
        ["0111", "7"], _
        ["1000", "8"], _
        ["1001", "9"], _
        ["1010", "A"], _
        ["1011", "B"], _
        ["1100", "C"], _
        ["1101", "D"], _
        ["1110", "E"], _
        ["1111", "F"]]
;
Global Const $aDOS_color[16] = [ _
        0xFF000000, _ ; 0x0 = 00 = Black
        0XFF000080, _ ; 0x1 = 01 = Blue
        0XFF008000, _ ; 0x2 = 02 = Green
        0XFF008080, _ ; 0x3 = 03 = Aqua
        0XFF800000, _ ; 0x4 = 04 = Red
        0XFF800080, _ ; 0x5 = 05 = Purple
        0XFF808000, _ ; 0x6 = 06 = Yellow
        0XFFC0C0C0, _ ; 0x7 = 07 = White
        0XFF808080, _ ; 0x8 = 08 = Gray
        0XFF0000FF, _ ; 0x9 = 09 = Light Blue
        0XFF00FF00, _ ; 0xA = 10 = Light Green
        0XFF00FFFF, _ ; 0xB = 11 = Light Aqua
        0XFFFF0000, _ ; 0xC = 12 = Light Red
        0XFFFF00FF, _ ; 0xD = 13 = Light Purple
        0XFFFFFF00, _ ; 0xE = 14 = Light Yellow
        0xFFFFFFFF];  ; 0xF = 15 = Bright White
;
Global $iPixSide = 1, _ ;   side of char's pixels
        $iVtab = 0, _ ; Vertical position of cursor
        $iHtab = 0, _ ; Horizontal position of cursor
        $iBG_DefaultColor = 0, _ ; Default Background color 0 = Black
        $iFG_DefaultColor = 10, _ ; Default Foreground color 7 = White
        $ahColors[2] = [ _ ; Array of brush handles
        _GDIPlus_BrushCreateSolid($aDOS_color[$iBG_DefaultColor]), _ ; default background for chars (Format AARRGGBB)
        _GDIPlus_BrushCreateSolid($aDOS_color[$iFG_DefaultColor])], _ ;   default foreground for chars.
        $iWidth, _ ; Width in bit of char
        $iHeight ;   height in bit of char

HotKeySet("{ESC}", "_Terminate")

; ------------------
Local $iWinWidth = 500
Local $iWinHeight = 400
Local $hScreen = GUICreate("", $iWinWidth, $iWinHeight, 10, 10)
GUISetState(@SW_SHOW, $hScreen)
Local $hCanvas = _GDIPlus_GraphicsCreateFromHWND($hScreen)
Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWinWidth, $iWinHeight)
Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2)
_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, 2)

Local $aFont, $tGraphic

While 1
    $aFont = _LoadFont()
    If IsArray($aFont) Then
        For $i = 0 To UBound($aFont) - 1 ; just for test, it prints all chars contained in the font
            _CharGen($hCanvas, $aFont[$i]); print a bitmapped char on the graphic object
            ; update cursor position
            $tGraphic = DllStructCreate("long width;long height", $hCanvas + 24) ; thanks to Danyfirex!
            $iHtab += ($iWidth * $iPixSide)
            If $iHtab > $tGraphic.width - ($iWidth * $iPixSide) Then
                $iVtab += ($iHeight * $iPixSide)
                $iHtab = 0
                If $iVtab > $tGraphic.height - ($iHeight * $iPixSide) Then $iVtab = 0
            EndIf
        Next
    EndIf
    _CharColor(Random(1, 15, 1)) ; random foreground color
WEnd

_Terminate()

Func _CharGen($hCanvas, $vBits, $iBase = 8)
    If IsArray($vBits) Then
        ; if argument is an array then third parameter is ignored since it can be inferred from array dim and array content itself
        For $iRow = UBound($vBits) - 1 To 0 Step -1 ; UBound of array is the number of rows
            For $iBit = StringLen($vBits[$iRow]) To 1 Step -1;StringLen of array's content is the number of horizontal pixels
                _GDIPlus_GraphicsFillRect($hCtxt, _ ; it draws a single pixel at a time
                        $iHtab + $iPixSide * $iBit, _ ; Horizontal pixel position within the matrix
                        $iVtab + $iPixSide * $iRow, _ ; Vertical pixel position within the matrix
                        $iPixSide, $iPixSide, _ ; pixel is a square
                        $ahColors[StringMid($vBits[$iRow], $iBit, 1)]) ; bit 0 = background; bit 1 = foreground
            Next ; next horizontal pixel
        Next ; next row
    Else
        For $iBit = StringLen($vBits) - 1 To 0 Step -1 ; get all bits one by one
            _GDIPlus_GraphicsFillRect($hCtxt, _ ; it draws a single pixel at a time
                    $iHtab + $iPixSide * Mod($iBit, $iBase), _ ;  Horizontal pixel position within the matrix
                    $iVtab + $iPixSide * Int($iBit / $iBase), _ ; Vertical pixel position within the matrix
                    $iPixSide, $iPixSide, _ ; pixel is a square
                    $ahColors[StringMid($vBits, $iBit + 1, 1)])
        Next
    EndIf
    _GDIPlus_GraphicsDrawImageRect($hCanvas, $hBitmap, 0, 0, $iWinWidth, $iWinHeight)
    Local Static $iCounter = 0
    _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\MatrixFont" & $iCounter & ".jpg")
    $iCounter += 1
EndFunc   ;==>_CharGen

; ------------------------------------------------------------
; set Background and foreground colors for chars
; for DOS style pass 0x00 to 0xFF as single argument
; for custom colors use 0xAARRGGBB format for both arguments
; for reset to default colors just call func without arguments
; ------------------------------------------------------------
Func _CharColor($vBackGr = "", $vForeGr = "")
    If $vBackGr == "" And $vForeGr == "" Then ; set default
        _GDIPlus_BrushSetSolidColor($ahColors[0], $aDOS_color[$iBG_DefaultColor]) ; background
        _GDIPlus_BrushSetSolidColor($ahColors[1], $aDOS_color[$iFG_DefaultColor]) ; foreground
    ElseIf $vBackGr < 256 And $vForeGr = "" Then ; set as in DOS (use 0xNN N_=backgroung _N=foreground)
        $vForeGr = Dec(Hex($vBackGr, 1))
        $vBackGr = Dec(StringLeft(String(Hex($vBackGr, 2)), 1))
        _GDIPlus_BrushSetSolidColor($ahColors[0], $aDOS_color[$vBackGr]) ; background
        _GDIPlus_BrushSetSolidColor($ahColors[1], $aDOS_color[$vForeGr]) ; foreground
    Else ; set custom colors
        _GDIPlus_BrushSetSolidColor($ahColors[0], $vBackGr) ; background
        _GDIPlus_BrushSetSolidColor($ahColors[1], $vForeGr) ; foreground
    EndIf
EndFunc   ;==>_CharColor

Func _LoadFont()
    ; Display an open dialog to select a list of file(s).
    Local $sFile = FileOpenDialog("Select a font file?", "", "All (*.c)", $FD_FILEMUSTEXIST)
    ;
    ; Read the file.c
    Local $hFile = FileOpen($sFile)
    Local $sFont = FileRead($hFile)
    FileClose($hFile)
    ;
    $aBytes = _StringBetween($sFont, "0x", ",") ; extract only binary bytes
    ;
    $iWidth = Dec($aBytes[0]) ; Width in bit of each single char
    $iHeight = Dec($aBytes[1]) ; height
    Local $iWhatis = Dec($aBytes[2]) ; ?
    Local $iChars = Dec($aBytes[3]) ; nr of chars in this font

    Local $iBytesPerChar = ($iWidth * $iHeight) / 8

    Local $aFontMatrix[$iChars]
    Local $aTemp[$iHeight]
    Local $iNdx0 = 0, $iNdx1 = 0
    ;
    ; Transform Hex bytes to binary digits
    For $i = 4 To UBound($aBytes) - 1
        $aTemp[$iNdx1] &= _TextToBinaryString($aBytes[$i])
        If StringLen($aTemp[$iNdx1]) = $iWidth Then
            $iNdx1 += 1
            If $iNdx1 < $iHeight Then
                $aTemp[$iNdx1] = ""
            Else
                $aFontMatrix[$iNdx0] = $aTemp
                $iNdx0 += 1
                $iNdx1 = 0
                $aTemp[$iNdx1] = ""
            EndIf
        EndIf
    Next
    Return $aFontMatrix
EndFunc   ;==>_LoadFont

Func _TextToBinaryString($sHexText)
    Local $sBits = ""
    For $i = 1 To StringLen($sHexText)
        $sBits &= $aNibbles[Dec(StringMid($sHexText, $i, 1))][0]
    Next
    Return $sBits
EndFunc   ;==>_TextToBinaryString

Func _Terminate()
    If WinActive($hScreen) Then
        ; Clean up resources
        _GDIPlus_GraphicsDispose($hCanvas)
        _GDIPlus_BrushDispose($ahColors[0])
        _GDIPlus_BrushDispose($ahColors[1])
        _GDIPlus_GraphicsDispose($hCtxt)
        _GDIPlus_BitmapDispose($hBitmap)
        _GDIPlus_Shutdown()
        MsgBox(0, "Debug", "Bye bye", 1)
        Exit
    EndIf
EndFunc   ;==>_Terminate

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks UEZ for the explanation and the example,
after few tryes I'm beginning to see the differencies between a graphic handle (just a "shadow" on the screen) and a  memory resident true bitmap (not viewable till you copy it from the memory to the graphic handle on the sceen...)

let me try more and digest these new "foods"...

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...