Jump to content

Reading pixels from Pic control


Recommended Posts

hi;

I'm trying to read pixels from a 1bpp pic control, and I failed :)

here is my failed code:

Func Get_Pixels()
    Local $iWidth, $iHeight, $cPixel, $bNum
    $iWidth = 128
    $iHeight = 64
    Local $hGfx1 = _GDIPlus_GraphicsCreateFromHWND(ControlGetHandle($GUI_MAIN, "LCD", $Pic1))
    Local $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGfx1)
    _GDIPlus_ImageSaveToFile($g_hBitmap, @ScriptDir & "LCD_Export.png"); just testing
    For $iRow = 0 To $iHeight - 1 Step 8 ; number of rows = 8
        For $iX = 0 To $iWidth - 1
            $bNum = 0
            For $iY = 0 To 7
                $cPixel = _GDIPlus_BitmapGetPixel($g_hBitmap, $iX, $iY + $iRow)
                If $cPixel <> 0 Then
                    $bNum += (2 ^ $iY)
                EndIf
            Next
            _ArrayAdd($arPixel, Hex($bNum, 2))
        Next
    Next
    _ArrayDisplay($arPixel, " test ")
EndFunc   ;==>Get_Pixels

$pic1 is the picture control I want to get its pixels.

I just want to test if the pixel is on/off, and then generate a binary value for every 8 pixel above each other

can any one help me plz, thanx
 

Link to comment
Share on other sites

The fastest way I found, in AutoIt, to get a pixel color in memory was using _GDIPlus_BitmapLockBits. Here's one I did a long time (made a lot of progress since then)

Since you've already got the handle to the bitmap there's not a lot left to do. I was trying to implement shade variation but you can forego that in your script.

Link to comment
Share on other sites

Thank you InunoTaishou for the quick reply

my problem in this script is, the file saved "LCD_Export.png" is blank, while the pic have data in it, and of course the array filled with Zeros

I'll try to modify it using  _GDIPlus_BitmapLockBits , but I think it wont work since the data is not there,  

I just hoped to have a quick fix for that :) 

 

Link to comment
Share on other sites

Oh I see. The reason why it's blank is because you're just creating a graphics object from the handle of the control. My apologies, I didn't read the full script.

I'm sure here's a message you can send to the picture control to get the bitmap object. I don't know what it is and I have to leave for work but perhaps @UEZ knows of a method.

Another quick fix would be to use the _ScreenCapture_CaptureWnd of the control handle, or just _ScreenCapture_Capture using the coordinates of the picture control.

Link to comment
Share on other sites

you can try something like this here:

 

...
$hHBITMAP = _SendMessage($hControl, $BM_GETIMAGE, 0, 0)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP)
_GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Test.png")
...

Don't forget to cleanup the resources!

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

Thank you all for the support.

thats what I did :

Func Get_Pixels()
    Local $iWidth, $iHeight, $cPixel, $bNum
    $iWidth = 128
    $iHeight = 64
    ;Local $hGfx1 = _GDIPlus_GraphicsCreateFromHWND(ControlGetHandle($GUI_MAIN, "LCD", $Pic1))
    Local $hControl = ControlGetHandle($GUI_MAIN, "", $Pic1)
    GUICtrlSetData($Msgs, $hControl); check the handle is ok
    Local $hHBITMAP = _SendMessage($hControl, $BM_GETIMAGE, 0, 0)
    Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP)
    _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\LCD_Test.png")
    For $iRow = 0 To $iHeight - 1 Step 8 ; number of rows = 64 / 8
        For $iX = 0 To $iWidth - 1
            $bNum = 0
            For $iY = 0 To 7
                $cPixel = _GDIPlus_BitmapGetPixel($hImage, $iX, $iY + $iRow)
                If $cPixel <> 0 Then
                    $bNum += (2 ^ $iY)
                EndIf
            Next
            _ArrayAdd($arPixel, Hex($bNum, 2))
        Next
    Next
    _ArrayDisplay($arPixel, " test ")
    _GDIPlus_BitmapDispose($hImage)
    _GDIPlus_BitmapDispose($hHBITMAP)
EndFunc   ;==>Get_Pixels

still no success , the "LCD_Test.png" is not even created !!!

there must be something I am missing , didn't know it is that hard to handle pic control :)

 

Link to comment
Share on other sites

From which GUI control you want to take the image? If it is your own GUI it makes no sense!

Furthermore did you startup GDI+?

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

Thank you UEZ for the fast reply

here is the full script so far:

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

#include <GDIPlus.au3>
#include <MemoryConstants.au3>
#include <Memory.au3>
#include <Misc.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>
#include <ScreenCapture.au3>

#Region ### GUI section ###
Global $GUI_MAIN = GUICreate("LCD", 435, 300, 192, 124)
Global $Pic1 = GUICtrlCreatePic("", 8, 50, 128, 64, $SS_SUNKEN + $SS_CENTERIMAGE + $SS_BITMAP)
Global $SetImg = GUICtrlCreateButton("Set TEXT", 8, 152, 75, 25)
Global $ClearScrn = GUICtrlCreateButton("Clear Image", 152, 152, 75, 25)
Global $rdStart = GUICtrlCreateButton("Read Image", 152, 50, 75, 25)
Global $Msgs = GUICtrlCreateLabel("Messages go here", 8, 30, 200, 20)
Global $TxT = GUICtrlCreateInput("Testing TEXT", 8, 120, 128, 20)
GUISetState(@SW_SHOW)
#EndRegion ### GUI section ###

Global $TempImg, $Text, $sFontName, $sFileName, $arPixel[0]
GUICtrlSetData($Msgs, $sFileName)
_GDIPlus_Startup()
Global $hBmp_Empty = _GDIPlus_BitmapCreateFromScan0(128, 64)
Global $hCtx_Empty = _GDIPlus_ImageGetGraphicsContext($hBmp_Empty)
_GDIPlus_GraphicsClear($hCtx_Empty, 0xFFF0F0F0)
Global $hHBmp_Empty = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp_Empty)
_GDIPlus_GraphicsDispose($hCtx_Empty)
_GDIPlus_BitmapDispose($hBmp_Empty)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($hHBmp_Empty)
            _GDIPlus_Shutdown()
            Exit
        Case $SetImg
            $Text = GUICtrlRead($TxT, 0)
            $TempImg = Draw_Text($Text)
            _WinAPI_DeleteObject(GUICtrlSendMsg($Pic1, 0x0172, 0, $TempImg))
            _WinAPI_DeleteObject($TempImg)
        Case $ClearScrn
            ; do something here to clear the image control
            _WinAPI_DeleteObject(GUICtrlSendMsg($Pic1, 0x0172, 0, $hHBmp_Empty))
        Case $rdStart
            Get_Pixels()
    EndSwitch
WEnd

Func Font_Set()
    Local $a_vFont = _ChooseFont()
    $sFontName = $a_vFont[2]
    ;Local $iFontSize = $a_vFont[3]
    ;Local $iColorRef = $a_vFont[5]
    ;Local $iFontWeight = $a_vFont[4]
    ;Local $bItalic = BitAND($a_vFont[1], 2)
    ;Local $bUnderline = BitAND($a_vFont[1], 4)
    ;Local $bStrikethru = BitAND($a_vFont[1], 8)
EndFunc   ;==>Font_Set

Func Image_AR()

EndFunc   ;==>Image_AR

Func Get_Pixels()
    Local $iWidth, $iHeight, $cPixel, $bNum
    $iWidth = 128
    $iHeight = 64
    ;Local $hGfx1 = _GDIPlus_GraphicsCreateFromHWND(ControlGetHandle($GUI_MAIN, "LCD", $Pic1))
    Local $hControl = ControlGetHandle($GUI_MAIN, "", $Pic1)
    GUICtrlSetData($Msgs, $hControl); check the handle is ok
    Local $hHBITMAP = _SendMessage($hControl, $BM_GETIMAGE, 0, 0)
    Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP)
    _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\LCD_Test.png")
    For $iRow = 0 To $iHeight - 1 Step 8 ; number of rows = 64 / 8
        For $iX = 0 To $iWidth - 1
            $bNum = 0
            For $iY = 0 To 7
                $cPixel = _GDIPlus_BitmapGetPixel($hImage, $iX, $iY + $iRow)
                If $cPixel <> 0 Then
                    $bNum += (2 ^ $iY)
                EndIf
            Next
            _ArrayAdd($arPixel, Hex($bNum, 2))
        Next
    Next
    _ArrayDisplay($arPixel, " test ")
    _GDIPlus_BitmapDispose($hImage)
    _GDIPlus_BitmapDispose($hHBITMAP)
EndFunc   ;==>Get_Pixels

Func Draw_Text($sString = "")
    Local $hGraphic, $hBrush, $hFormat, _
            $hFamily, $hFont, $tLayout, _
            $aInfo, $hBitmap, $FontSize, _
            $iWidth, $iHeight, $fontStyle, _
            $hImage
    $iWidth = 128
    $iHeight = 64
    $FontSize = 11
    $fontStyle = 1
    $hImage = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $GDIP_PXF01INDEXED)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iWidth, $iHeight, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("consolas")
    $hFont = _GDIPlus_FontCreate($hFamily, $FontSize, $fontStyle)
    $tLayout = _GDIPlus_RectFCreate($iWidth / 2 / 5, $iHeight / 3, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BitmapDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    Return $hBitmap
EndFunc   ;==>Draw_Text

 

Link to comment
Share on other sites

Try this:

;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

#include <GDIPlus.au3>
#include <MemoryConstants.au3>
#include <Memory.au3>
#include <Misc.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>
#include <ScreenCapture.au3>

#Region ### GUI section ###
Global $GUI_MAIN = GUICreate("LCD", 435, 300, 192, 124)
Global $Pic1 = GUICtrlCreatePic("", 8, 50, 128, 64, $SS_SUNKEN + $SS_CENTERIMAGE + $SS_BITMAP)
Global $SetImg = GUICtrlCreateButton("Set TEXT", 8, 152, 75, 25)
Global $ClearScrn = GUICtrlCreateButton("Clear Image", 152, 152, 75, 25)
Global $rdStart = GUICtrlCreateButton("Read Image", 152, 50, 75, 25)
Global $Msgs = GUICtrlCreateLabel("Messages go here", 8, 30, 200, 20)
Global $TxT = GUICtrlCreateInput("Testing TEXT", 8, 120, 128, 20)
GUISetState(@SW_SHOW)
#EndRegion ### GUI section ###

Global $aBitmaps, $Text, $sFontName, $sFileName, $arPixel[0]
GUICtrlSetData($Msgs, $sFileName)
_GDIPlus_Startup()
Global $hBmp_Empty = _GDIPlus_BitmapCreateFromScan0(128, 64)
Global $hCtx_Empty = _GDIPlus_ImageGetGraphicsContext($hBmp_Empty)
_GDIPlus_GraphicsClear($hCtx_Empty, 0xFFF0F0F0)
Global $hHBmp_Empty = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp_Empty)
_GDIPlus_GraphicsDispose($hCtx_Empty)
_GDIPlus_BitmapDispose($hBmp_Empty)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($hHBmp_Empty)
            _GDIPlus_ImageDispose($hBmp_Empty)
            If IsArray($aBitmaps) Then
                _WinAPI_DeleteObject($aBitmaps[0])
                _GDIPlus_ImageDispose($aBitmaps[1])
            EndIf
            _GDIPlus_Shutdown()
            Exit
        Case $SetImg
            $Text = GUICtrlRead($TxT, 0)
            If IsArray($aBitmaps) Then
                _WinAPI_DeleteObject($aBitmaps[0])
                _GDIPlus_ImageDispose($aBitmaps[1])
            EndIf
            $aBitmaps = Draw_Text($Text)
            _WinAPI_DeleteObject(GUICtrlSendMsg($Pic1, 0x0172, 0, $aBitmaps[0]))

        Case $ClearScrn
            ; do something here to clear the image control
            _WinAPI_DeleteObject(GUICtrlSendMsg($Pic1, 0x0172, 0, $hHBmp_Empty))
        Case $rdStart
            Get_Pixels()
    EndSwitch
WEnd

Func Font_Set()
    Local $a_vFont = _ChooseFont()
    $sFontName = $a_vFont[2]
    ;Local $iFontSize = $a_vFont[3]
    ;Local $iColorRef = $a_vFont[5]
    ;Local $iFontWeight = $a_vFont[4]
    ;Local $bItalic = BitAND($a_vFont[1], 2)
    ;Local $bUnderline = BitAND($a_vFont[1], 4)
    ;Local $bStrikethru = BitAND($a_vFont[1], 8)
EndFunc   ;==>Font_Set

Func Image_AR()

EndFunc   ;==>Image_AR

Func Get_Pixels()
    If IsArray($aBitmaps) Then
        Return _GDIPlus_ImageSaveToFile($aBitmaps[1], @ScriptDir & "\LCD_Test.png")
    EndIf
    Return 0
EndFunc   ;==>Get_Pixels

Func Draw_Text($sString = "")
    Local $hGraphic, $hBrush, $hFormat, _
            $hFamily, $hFont, $tLayout, _
            $aInfo, $hBitmap, $FontSize, _
            $iWidth, $iHeight, $fontStyle, _
            $hImage
    $iWidth = 128
    $iHeight = 64
    $FontSize = 11
    $fontStyle = 1
    $hImage = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $GDIP_PXF01INDEXED)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iWidth, $iHeight, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("consolas")
    $hFont = _GDIPlus_FontCreate($hFamily, $FontSize, $fontStyle)
    $tLayout = _GDIPlus_RectFCreate($iWidth / 2 / 5, $iHeight / 3, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    Local $aBitmaps[2] = [$hBitmap, $hImage]
    Return $aBitmaps
EndFunc   ;==>Draw_Text

 

You thought too complicated. ;)

 

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

hahahaha, my thoughts too complicated for a reason ;)

my aim is not to save the contents of the pic control, but to get every pixel of it into an array, then save the array.

that is why I made these loops to construct an array based on that pic contents as I said in my first post.

but u already solved a great deal of the problem, I'll try to get the data out of the array u constructed, wish me success :)

and thank you very much UEZ

Link to comment
Share on other sites

I finally made it, thanx UEZ for the support

here is the final script, maybe someone find it useful ;)

;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#include <GDIPlus.au3>
#include <MemoryConstants.au3>
#include <Memory.au3>
#include <Misc.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>
#include <File.au3>
#Region ### GUI section ###
Global $GUI_MAIN = GUICreate("LCD Designer", 300, 200, 192, 124)
Global $Pic1 = GUICtrlCreatePic("", 8, 50, 128, 64, $SS_SUNKEN + $SS_CENTERIMAGE + $SS_BITMAP)
Global $fSize = GUICtrlCreateInput("11", 152, 50, 50, 20)
GUICtrlCreateUpdown($fSize)
Local $sLable1 = GUICtrlCreateLabel("Font Size", 210, 53)
Global $fSet = GUICtrlCreateButton("Select Font", 152, 80, 75, 25)
Global $SetImg = GUICtrlCreateButton("Set TEXT", 8, 152, 75, 25)
Global $ClearScrn = GUICtrlCreateButton("Clear Image", 152, 152, 75, 25)
Global $rdStart = GUICtrlCreateButton("Save Image", 152, 115, 75, 25)
Global $Msgs = GUICtrlCreateLabel("Messages go here", 8, 30, 200, 20)
Global $TxT = GUICtrlCreateInput("الله لا اله الا هو", 8, 120, 128, 20)
GUISetState(@SW_SHOW)
#EndRegion ### GUI section ###
; you can use this to add custom text on a 128 x 64 pixel LCD
; generated file is a hex dump witch u can use in your uC program
; to be displayed on LCD interface
; you may modify it to load any 1bpp image you may create
; just put in mind to use .png format
; it is not a fancy script, but it do the job :)
; special Thanks to UEZ for the great help
Global $aBitmaps, $Text, $sFontName, $iFontSize, $sFileName, $arPixel[0]
$sFontName = "consolas" ; defult font
$iFontSize = 11 ; defult size
;GUICtrlSetData($Msgs, $sFileName)
_GDIPlus_Startup()
Global $hBmp_Empty = _GDIPlus_BitmapCreateFromScan0(128, 64)
Global $hCtx_Empty = _GDIPlus_ImageGetGraphicsContext($hBmp_Empty)
_GDIPlus_GraphicsClear($hCtx_Empty, 0xFFF0F0F0)
Global $hHBmp_Empty = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp_Empty)
_GDIPlus_GraphicsDispose($hCtx_Empty)
_GDIPlus_BitmapDispose($hBmp_Empty)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($hHBmp_Empty)
            _GDIPlus_ImageDispose($hBmp_Empty)
            If IsArray($aBitmaps) Then
                _WinAPI_DeleteObject($aBitmaps[0])
                _GDIPlus_ImageDispose($aBitmaps[1])
            EndIf
            _GDIPlus_Shutdown()
            Exit
        Case $SetImg
            $Text = GUICtrlRead($TxT, 0)
            If IsArray($aBitmaps) Then
                _WinAPI_DeleteObject($aBitmaps[0])
                _GDIPlus_ImageDispose($aBitmaps[1])
            EndIf
            $aBitmaps = Draw_Text($Text)
            _WinAPI_DeleteObject(GUICtrlSendMsg($Pic1, 0x0172, 0, $aBitmaps[0]))

        Case $ClearScrn
            _WinAPI_DeleteObject(GUICtrlSendMsg($Pic1, 0x0172, 0, $hHBmp_Empty))
        Case $rdStart
            Get_Pixels()
        Case $fSet
            Font_Set()
    EndSwitch
WEnd

Func Font_Set()
    Local $a_vFont = _ChooseFont($sFontName, $iFontSize)
    $sFontName = $a_vFont[2]
    $iFontSize = $a_vFont[3]
    GUICtrlSetData($fSize, $iFontSize)
    ;Local $iColorRef = $a_vFont[5]
    ;Local $iFontWeight = $a_vFont[4]
    ;Local $bItalic = BitAND($a_vFont[1], 2)
    ;Local $bUnderline = BitAND($a_vFont[1], 4)
    ;Local $bStrikethru = BitAND($a_vFont[1], 8)
EndFunc   ;==>Font_Set

Func Get_Pixels()
    Local $iWidth, $iHeight, $cPixel, $bNum
    $iWidth = 128
    $iHeight = 64
    If IsArray($aBitmaps) Then ; comment the if statment if u want to use your own image and press [Save Image]
        _GDIPlus_ImageSaveToFile($aBitmaps[1], @ScriptDir & "\LCD_Tmp.png")
    EndIf
    $hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\LCD_Tmp.png") ; modify to the name of your image file
    For $iRow = 0 To $iHeight - 1 Step 8 ; number of rows = 64 / 8
        For $iX = 0 To $iWidth - 1
            $bNum = 0
            For $iY = 0 To 7
                $cPixel = _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY + $iRow)
                $cPixel = BitAND($cPixel, 0xFFFFFF)
                If $cPixel = 0 Then
                    $bNum += (2 ^ $iY)
                EndIf
            Next
            _ArrayAdd($arPixel, "0x" & Hex($bNum, 2))
        Next
    Next
    ;_ArrayDisplay($arPixel, " test ")
    _GDIPlus_ImageDispose($hBitmap)
    $sFileName = FileSaveDialog(" Save TO ", @ScriptDir, "Text Files (*.txt)", $FD_PROMPTOVERWRITE, "LCD_Dump.txt")
    FileOpen($sFileName, $FO_OVERWRITE + $FO_BINARY)
    FileWrite($sFileName, "// 128 x 64 Pixel LCD Array (1024 byte)" & @CRLF)
    $cItems = 0
    For $x = 0 To UBound($arPixel) - 1
        $cItems += 1
        If $cItems < 16 Then
            FileWrite($sFileName, $arPixel[$x] & ",")
        Else
            FileWrite($sFileName, $arPixel[$x] & "," & @CRLF)
            $cItems = 0
        EndIf
    Next
    FileClose($sFileName)
    Return 0
EndFunc   ;==>Get_Pixels

Func Draw_Text($sString = "")
    Local $hGraphic, $hBrush, $hFormat, _
            $hFamily, $hFont, $tLayout, _
            $aInfo, $hBitmap, $FontSize, _
            $iWidth, $iHeight, $fontStyle, _
            $hImage
    $iWidth = 128
    $iHeight = 64
    $FontSize = GUICtrlRead($fSize, 0)
    $fontStyle = 1
    $hImage = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $GDIP_PXF01INDEXED)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iWidth, $iHeight, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate($sFontName)
    $hFont = _GDIPlus_FontCreate($hFamily, $FontSize, $fontStyle)
    $tLayout = _GDIPlus_RectFCreate($iWidth / 2 / 5, $iHeight / 3, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    Local $aBitmaps[2] = [$hBitmap, $hImage]
    Return $aBitmaps
EndFunc   ;==>Draw_Text

 

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...