Sign in to follow this  
Followers 0
RagsRevenge

Load_BMP_From_Mem (SOLVED)

8 posts in this topic

#1 ·  Posted (edited)

I'm trying to tidy up the installation of 1 of my scripts. 1 of the things I'd like to do is load the required BMPs from memory, as opposed to from file. I have the following code, but I don't know what I need to do with the bitmap stream to enable me to use it on a button. My experiments allow me to draw the BMP to the GUI, but not as a button image.

Thanks for any help.

D

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIplus.au3>
#include <Memory.au3>
#include <ButtonConstants.au3>

_GDIPlus_Startup()
Global $bitmap_from_file
;Local $image = 

$bitmap_from_file = Load_BMP_From_Mem(imButExp())

;$saveFile = _GDIPlus_ImageSaveToFile ($bitmap_from_file, "c:\temp\Travel1DC.bmp")
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 267, 250, 193, 125)
GUICtrlCreateButton("", 10, 15, 44, 44, $BS_BITMAP )
GUICtrlSetImage(-1, $bitmap_from_file)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

#cs Experimentation
Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
Local $bg_w = 10, $bg_h = 60
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(100, 100, $hGraphic)
Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hContext)
_GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, 100, 100)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 97, 30, 100, 100)
local $hGUI = WinGetHandle("Form1")
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
#ce

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
;$saveFile = _GDIPlus_ImageSaveToFile ($bitmap_from_file, "c:\temp\Travel1DC.bmp")  ;works!!!
_GDIPlus_Shutdown()

Func Load_BMP_From_Mem($pic) ;coded by UEZ. Thanks to ProgAndy for mem allocation lines
    Local $memBitmap, $len, $tMem, $hImage, $hData, $pData, $hStream, $hBitmapFromStream
    $memBitmap = Binary($pic) ;load image  saved in variable (memory) and convert it to binary
    $len =  BinaryLen($memBitmap) ;get length of image

    $hData  = _MemGlobalAlloc($len, 0x0002) ;allocates movable memory  ($GMEM_MOVEABLE = 0x0002)
    $pData = _MemGlobalLock($hData)  ;translate the handle into a pointer
    $tMem =  DllStructCreate("byte[" & $len & "]", $pData) ;create struct
     DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data
    _MemGlobalUnlock($hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE

    $hStream = _WinAPI_CreateStreamOnHGlobal($pData) ;Creates a stream object that uses an HGLOBAL memory handle to store the stream contents
    $hBitmapFromStream = _GDIPlus_BitmapCreateFromStream($hStream) ;Creates a Bitmap object based on an IStream COM interface
    $tMem = ""
    Return $hBitmapFromStream
EndFunc

Func _WinAPI_CreateStreamOnHGlobal($hGlobal = 0, $fDeleteOnRelease = True)
    Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "hwnd", $hGlobal, "int", $fDeleteOnRelease, "ptr*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[3]
EndFunc   ;==>_WinAPI_CreateStreamOnHGlobal

Func _GDIPlus_BitmapCreateFromStream($pStream)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_BitmapCreateFromStream

Func imButExp()
    Local $text = ''
    $text &= '0x424DF406000000000000360400002800000019000000190000000100080000000000BE020000120B0000120B000000000000000000000000000001010100020202000303030004040400'
    $text &= '05050500060606000707070008080800090909000A0A0A000B0B0B000C0C0C000D0D0D000E0E0E000F0F0F0010101000111111001212120013131300141414001515150016161600171717'
    $text &= '0018181800191919001A1A1A001B1B1B001C1C1C001D1D1D001E1E1E001F1F1F00202020002121210022222200232323002424240025252500262626002727270028282800292929002A2A'
    $text &= '2A002B2B2B002C2C2C002D2D2D002E2E2E002F2F2F00303030003131310032323200333333003434340035353500363636003737370038383800393939003A3A3A003B3B3B003C3C3C003D'
    $text &= '3D3D003E3E3E003F3F3F00404040004141410042424200434343004444440045454500464646004747470048484800494949004A4A4A004B4B4B004C4C4C004D4D4D004E4E4E004F4F4F00'
    $text &= '505050005151510052525200535353005454540055555500565656005757570058585800595959005A5A5A005B5B5B005C5C5C005D5D5D005E5E5E005F5F5F006060600061616100626262'
    $text &= '00636363006464640065656500666666006767670068686800696969006A6A6A006B6B6B006C6C6C006D6D6D006E6E6E006F6F6F0070707000717171007272720073737300747474007575'
    $text &= '7500767676007777770078787800797979007A7A7A007B7B7B007C7C7C007D7D7D007E7E7E007F7F7F00808080008181810082828200838383008484840085858500868686008787870088'
    $text &= '888800898989008A8A8A008B8B8B008C8C8C008D8D8D008E8E8E008F8F8F00909090009191910092929200939393009494940095959500969696009797970098989800999999009A9A9A00'
    $text &= '9B9B9B009C9C9C009D9D9D009E9E9E009F9F9F00A0A0A000A1A1A100A2A2A200A3A3A300A4A4A400A5A5A500A6A6A600A7A7A700A8A8A800A9A9A900AAAAAA00ABABAB00ACACAC00ADADAD'
    $text &= '00AEAEAE00AFAFAF00B0B0B000B1B1B100B2B2B200B3B3B300B4B4B400B5B5B500B6B6B600B7B7B700B8B8B800B9B9B900BABABA00BBBBBB00BCBCBC00BDBDBD00BEBEBE00BFBFBF00C0C0'
    $text &= 'C000C1C1C100C2C2C200C3C3C300C4C4C400C5C5C500C6C6C600C7C7C700C8C8C800C9C9C900CACACA00CBCBCB00CCCCCC00CDCDCD00CECECE00CFCFCF00D0D0D000D1D1D100D2D2D200D3'
    $text &= 'D3D300D4D4D400D5D5D500D6D6D600D7D7D700D8D8D800D9D9D900DADADA00DBDBDB00DCDCDC00DDDDDD00DEDEDE00DFDFDF00E0E0E000E1E1E100E2E2E200E3E3E300E4E4E400E5E5E500'
    $text &= 'E6E6E600E7E7E700E8E8E800E9E9E900EAEAEA00EBEBEB00ECECEC00EDEDED00EEEEEE00EFEFEF00F0F0F000F1F1F100F2F2F200F3F3F300F4F4F400F5F5F500F6F6F600F7F7F700F8F8F8'
    $text &= '00F9F9F900FAFAFA00FBFBFB00FCFCFC00FDFDFD00FEFEFE00FFFFFF00E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4'
    $text &= 'E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4E4E4E4E4E4E4EAE4E4E4E4E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4C9B7B0B3A79AA2AFB2B4C1E4E4E4E4E4E4E4000000E4E4E4E4E4F0C9967E'
    $text &= '767B8187847E7C7B8BC3E4E4E4E4E4E4000000E4E4E4E4F5B08B8986888C90928F8B8B898987ACE4E4E4E4E4000000E4E4E4EDCA8C77898F94989A9B9A9898938C7889C4E4E4E4E4000000'
    $text &= 'E4E4E4CC998A8993979B9FA2A3A4A3A19C968F8C8CC1E4E4E4000000E4E4E4B9808990969DA3A7ABACADABA8A59F988C7CB6E4E4E4000000E4E4E4B2798C969BA4ACB1B6B7B8B6B4B0ABA1'
    $text &= '927FB4E4E4E4000000E4E4E4B77D8F9AA1AAB2BABEBFC1C2C1BCB4A99884B4E4E4E4000000E4E4E0A883929FA7B0BAC2CACCD0D0CDC6BDB2A18DA8EAE4E4000000E4E8BF998794A1ABB4BF'
    $text &= 'C8D3D9DDDCD7CEC4B9A7939FE4E4E4000000E4E4E0A98493A2AEB9C5CDD9E2E7E9E4DBCEBFA891AEE4E4E4000000E4E4E4B77F91A1AEBBC9D2E0EBF2F5F3E9D7C2A68BBAE4E4E4000000E4'
    $text &= 'E4E4B17A8FA0ACB9CAD8E8F4FBFDFDF3DEC4A485B5E4E4E4000000E4E4E4C18D8E98A8B6C7D7E9F6FFFFFFF8DABB9F8DBCE4E4E4000000E4E4E4DDB1928FA3B0C0CEE0EFFBFFFFEECBAB9D'
    $text &= 'A5D0E4E4E4000000E4E4E4E4D89B8596A4B6C2D1DDEBEEE7D1B2949DD1E4E4E4E4000000E4E4E4E4E4BF9E9B9BA2AABAC9D2D1C7B4A59FBCE4E4E4E4E4000000E4E4E4E4E4E4DAB698878C'
    $text &= 'A5BFBDB4B1AAAED3E4E4E4E4E4E4000000E4E4E4E4E4E4E4DFC6B6B9BCBEC6CDCFCED5E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4000000E4E4'
    $text &= 'E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E40000000000'
    Return $text
EndFunc
Edited by RagsRevenge

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

Use GUICtrlSendMsg() ..

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIplus.au3>
#include <Memory.au3>
#include <ButtonConstants.au3>

Global Const $IMAGE_BITMAP = 0 ; Added for GUICtrlSendMsg()

Global $bitmap_from_file

_GDIPlus_Startup()

$bitmap_from_file = Load_BMP_From_Mem(imButExp())


;$saveFile = _GDIPlus_ImageSaveToFile ($bitmap_from_file, "c:\temp\Travel1DC.bmp")
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 267, 250, 193, 125)
$iButton = GUICtrlCreateButton("", 10, 15, 44, 44, $BS_BITMAP)

; Added this, also changed return in Load_BMP_From_Mem() function , see below.
GUICtrlSendMsg($iButton, $BM_SETIMAGE, $IMAGE_BITMAP, $bitmap_from_file)

;~ GUICtrlSetImage(-1, $bitmap_from_file)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

#cs Experimentation
Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
Local $bg_w = 10, $bg_h = 60
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(100, 100, $hGraphic)
Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hContext)
_GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, 100, 100)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 97, 30, 100, 100)
local $hGUI = WinGetHandle("Form1")
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
#ce

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
;$saveFile = _GDIPlus_ImageSaveToFile ($bitmap_from_file, "c:\temp\Travel1DC.bmp")  ;works!!!
_GDIPlus_Shutdown()

Func Load_BMP_From_Mem($pic) ;coded by UEZ. Thanks to ProgAndy for mem allocation lines
    Local $memBitmap, $len, $tMem, $hImage, $hData, $pData, $hStream, $hBitmapFromStream, $hBitmap
    $memBitmap = Binary($pic) ;load image  saved in variable (memory) and convert it to binary
    $len =  BinaryLen($memBitmap) ;get length of image

    $hData  = _MemGlobalAlloc($len, 0x0002) ;allocates movable memory  ($GMEM_MOVEABLE = 0x0002)
    $pData = _MemGlobalLock($hData)  ;translate the handle into a pointer
    $tMem =  DllStructCreate("byte[" & $len & "]", $pData) ;create struct
     DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data
    _MemGlobalUnlock($hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE
    $hStream = _WinAPI_CreateStreamOnHGlobal($pData) ;Creates a stream object that uses an HGLOBAL memory handle to store the stream contents
    $hBitmapFromStream = _GDIPlus_BitmapCreateFromStream($hStream) ;Creates a Bitmap object based on an IStream COM interface

    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmapFromStream) ;Create HBITMAP
    _GDIPlus_ImageDispose($hBitmapFromStream) ; Dispose of $hBitmapFromStream object

    $tMem = ""
    Return $hBitmap ; Return HBITMAP
EndFunc

Func _WinAPI_CreateStreamOnHGlobal($hGlobal = 0, $fDeleteOnRelease = True)
    Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "hwnd", $hGlobal, "int", $fDeleteOnRelease, "ptr*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[3]
EndFunc   ;==>_WinAPI_CreateStreamOnHGlobal

Func _GDIPlus_BitmapCreateFromStream($pStream)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_BitmapCreateFromStream

Func imButExp()
    Local $text = ''
    $text &= '0x424DF406000000000000360400002800000019000000190000000100080000000000BE020000120B0000120B000000000000000000000000000001010100020202000303030004040400'
    $text &= '05050500060606000707070008080800090909000A0A0A000B0B0B000C0C0C000D0D0D000E0E0E000F0F0F0010101000111111001212120013131300141414001515150016161600171717'
    $text &= '0018181800191919001A1A1A001B1B1B001C1C1C001D1D1D001E1E1E001F1F1F00202020002121210022222200232323002424240025252500262626002727270028282800292929002A2A'
    $text &= '2A002B2B2B002C2C2C002D2D2D002E2E2E002F2F2F00303030003131310032323200333333003434340035353500363636003737370038383800393939003A3A3A003B3B3B003C3C3C003D'
    $text &= '3D3D003E3E3E003F3F3F00404040004141410042424200434343004444440045454500464646004747470048484800494949004A4A4A004B4B4B004C4C4C004D4D4D004E4E4E004F4F4F00'
    $text &= '505050005151510052525200535353005454540055555500565656005757570058585800595959005A5A5A005B5B5B005C5C5C005D5D5D005E5E5E005F5F5F006060600061616100626262'
    $text &= '00636363006464640065656500666666006767670068686800696969006A6A6A006B6B6B006C6C6C006D6D6D006E6E6E006F6F6F0070707000717171007272720073737300747474007575'
    $text &= '7500767676007777770078787800797979007A7A7A007B7B7B007C7C7C007D7D7D007E7E7E007F7F7F00808080008181810082828200838383008484840085858500868686008787870088'
    $text &= '888800898989008A8A8A008B8B8B008C8C8C008D8D8D008E8E8E008F8F8F00909090009191910092929200939393009494940095959500969696009797970098989800999999009A9A9A00'
    $text &= '9B9B9B009C9C9C009D9D9D009E9E9E009F9F9F00A0A0A000A1A1A100A2A2A200A3A3A300A4A4A400A5A5A500A6A6A600A7A7A700A8A8A800A9A9A900AAAAAA00ABABAB00ACACAC00ADADAD'
    $text &= '00AEAEAE00AFAFAF00B0B0B000B1B1B100B2B2B200B3B3B300B4B4B400B5B5B500B6B6B600B7B7B700B8B8B800B9B9B900BABABA00BBBBBB00BCBCBC00BDBDBD00BEBEBE00BFBFBF00C0C0'
    $text &= 'C000C1C1C100C2C2C200C3C3C300C4C4C400C5C5C500C6C6C600C7C7C700C8C8C800C9C9C900CACACA00CBCBCB00CCCCCC00CDCDCD00CECECE00CFCFCF00D0D0D000D1D1D100D2D2D200D3'
    $text &= 'D3D300D4D4D400D5D5D500D6D6D600D7D7D700D8D8D800D9D9D900DADADA00DBDBDB00DCDCDC00DDDDDD00DEDEDE00DFDFDF00E0E0E000E1E1E100E2E2E200E3E3E300E4E4E400E5E5E500'
    $text &= 'E6E6E600E7E7E700E8E8E800E9E9E900EAEAEA00EBEBEB00ECECEC00EDEDED00EEEEEE00EFEFEF00F0F0F000F1F1F100F2F2F200F3F3F300F4F4F400F5F5F500F6F6F600F7F7F700F8F8F8'
    $text &= '00F9F9F900FAFAFA00FBFBFB00FCFCFC00FDFDFD00FEFEFE00FFFFFF00E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4'
    $text &= 'E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4E4E4E4E4E4E4EAE4E4E4E4E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4C9B7B0B3A79AA2AFB2B4C1E4E4E4E4E4E4E4000000E4E4E4E4E4F0C9967E'
    $text &= '767B8187847E7C7B8BC3E4E4E4E4E4E4000000E4E4E4E4F5B08B8986888C90928F8B8B898987ACE4E4E4E4E4000000E4E4E4EDCA8C77898F94989A9B9A9898938C7889C4E4E4E4E4000000'
    $text &= 'E4E4E4CC998A8993979B9FA2A3A4A3A19C968F8C8CC1E4E4E4000000E4E4E4B9808990969DA3A7ABACADABA8A59F988C7CB6E4E4E4000000E4E4E4B2798C969BA4ACB1B6B7B8B6B4B0ABA1'
    $text &= '927FB4E4E4E4000000E4E4E4B77D8F9AA1AAB2BABEBFC1C2C1BCB4A99884B4E4E4E4000000E4E4E0A883929FA7B0BAC2CACCD0D0CDC6BDB2A18DA8EAE4E4000000E4E8BF998794A1ABB4BF'
    $text &= 'C8D3D9DDDCD7CEC4B9A7939FE4E4E4000000E4E4E0A98493A2AEB9C5CDD9E2E7E9E4DBCEBFA891AEE4E4E4000000E4E4E4B77F91A1AEBBC9D2E0EBF2F5F3E9D7C2A68BBAE4E4E4000000E4'
    $text &= 'E4E4B17A8FA0ACB9CAD8E8F4FBFDFDF3DEC4A485B5E4E4E4000000E4E4E4C18D8E98A8B6C7D7E9F6FFFFFFF8DABB9F8DBCE4E4E4000000E4E4E4DDB1928FA3B0C0CEE0EFFBFFFFEECBAB9D'
    $text &= 'A5D0E4E4E4000000E4E4E4E4D89B8596A4B6C2D1DDEBEEE7D1B2949DD1E4E4E4E4000000E4E4E4E4E4BF9E9B9BA2AABAC9D2D1C7B4A59FBCE4E4E4E4E4000000E4E4E4E4E4E4DAB698878C'
    $text &= 'A5BFBDB4B1AAAED3E4E4E4E4E4E4000000E4E4E4E4E4E4E4DFC6B6B9BCBEC6CDCFCED5E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4000000E4E4'
    $text &= 'E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E40000000000'
    Return $text
EndFunc

Cheers

Edited by smashly

Share this post


Link to post
Share on other sites

Thanks Smashly (and UEZ & ProgAndy),

I've been trying to figure that out on and off for weeks.

Here's cleaned up code for others looking for a solution.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIplus.au3>
#include <Memory.au3>
#include <ButtonConstants.au3>

Global Const $IMAGE_BITMAP = 0 ; Added for GUICtrlSendMsg()
Global $bitmap_from_file

_GDIPlus_Startup()

$bitmap_from_file = Load_BMP_From_Mem_Return_hBitmap(imButExp())

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 267, 250, 193, 125)
$iButton = GUICtrlCreateButton("", 10, 15, 44, 44, $BS_BITMAP)
$iButton2 = GUICtrlCreateButton("", 10, 105, 44, 44, $BS_BITMAP)

GUICtrlSendMsg($iButton, $BM_SETIMAGE, $IMAGE_BITMAP, $bitmap_from_file)
GUICtrlSendMsg($iButton2, $BM_SETIMAGE, $IMAGE_BITMAP, $bitmap_from_file)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_Shutdown()
            Exit

    EndSwitch
WEnd

Func Load_BMP_From_Mem_Return_hBitmap($pic)
    Local $hBitmap, $h_BitmapFromStream
    $h_BitmapFromStream = Load_BMP_From_Mem($pic)

    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($h_BitmapFromStream) ;Create HBITMAP
    _GDIPlus_ImageDispose($h_BitmapFromStream) ; Dispose of $hBitmapFromStream object

    Return $hBitmap ; Return HBITMAP
EndFunc

Func Load_BMP_From_Mem($pic) ;coded by UEZ. Thanks to ProgAndy for mem allocation lines
    Local $memBitmap, $len, $tMem, $hImage
    $memBitmap = Binary($pic) ;load image saved in variable (memory) and convert it to binary
    $len = BinaryLen($memBitmap) ;get length of image

    $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory ($GMEM_MOVEABLE = 0x0002)
    $pData = _MemGlobalLock($hData) ;translate the handle into a pointer
    $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct
    DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data
    _MemGlobalUnlock($hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE

    $hStream = _WinAPI_CreateStreamOnHGlobal($pData) ;Creates a stream object that uses an HGLOBAL memory handle to store the stream contents
    $hBitmapFromStream = _GDIPlus_BitmapCreateFromStream($hStream) ;Creates a Bitmap object based on an IStream COM interface
    $tMem = ""
    Return $hBitmapFromStream
EndFunc

Func _WinAPI_CreateStreamOnHGlobal($hGlobal = 0, $fDeleteOnRelease = True)
    Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "hwnd", $hGlobal, "int", $fDeleteOnRelease, "ptr*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[3]
EndFunc   ;==>_WinAPI_CreateStreamOnHGlobal

Func _GDIPlus_BitmapCreateFromStream($pStream)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_BitmapCreateFromStream

Func imButExp()
    Local $text = ''
    $text &= '0x424DF406000000000000360400002800000019000000190000000100080000000000BE020000120B0000120B000000000000000000000000000001010100020202000303030004040400'
    $text &= '05050500060606000707070008080800090909000A0A0A000B0B0B000C0C0C000D0D0D000E0E0E000F0F0F0010101000111111001212120013131300141414001515150016161600171717'
    $text &= '0018181800191919001A1A1A001B1B1B001C1C1C001D1D1D001E1E1E001F1F1F00202020002121210022222200232323002424240025252500262626002727270028282800292929002A2A'
    $text &= '2A002B2B2B002C2C2C002D2D2D002E2E2E002F2F2F00303030003131310032323200333333003434340035353500363636003737370038383800393939003A3A3A003B3B3B003C3C3C003D'
    $text &= '3D3D003E3E3E003F3F3F00404040004141410042424200434343004444440045454500464646004747470048484800494949004A4A4A004B4B4B004C4C4C004D4D4D004E4E4E004F4F4F00'
    $text &= '505050005151510052525200535353005454540055555500565656005757570058585800595959005A5A5A005B5B5B005C5C5C005D5D5D005E5E5E005F5F5F006060600061616100626262'
    $text &= '00636363006464640065656500666666006767670068686800696969006A6A6A006B6B6B006C6C6C006D6D6D006E6E6E006F6F6F0070707000717171007272720073737300747474007575'
    $text &= '7500767676007777770078787800797979007A7A7A007B7B7B007C7C7C007D7D7D007E7E7E007F7F7F00808080008181810082828200838383008484840085858500868686008787870088'
    $text &= '888800898989008A8A8A008B8B8B008C8C8C008D8D8D008E8E8E008F8F8F00909090009191910092929200939393009494940095959500969696009797970098989800999999009A9A9A00'
    $text &= '9B9B9B009C9C9C009D9D9D009E9E9E009F9F9F00A0A0A000A1A1A100A2A2A200A3A3A300A4A4A400A5A5A500A6A6A600A7A7A700A8A8A800A9A9A900AAAAAA00ABABAB00ACACAC00ADADAD'
    $text &= '00AEAEAE00AFAFAF00B0B0B000B1B1B100B2B2B200B3B3B300B4B4B400B5B5B500B6B6B600B7B7B700B8B8B800B9B9B900BABABA00BBBBBB00BCBCBC00BDBDBD00BEBEBE00BFBFBF00C0C0'
    $text &= 'C000C1C1C100C2C2C200C3C3C300C4C4C400C5C5C500C6C6C600C7C7C700C8C8C800C9C9C900CACACA00CBCBCB00CCCCCC00CDCDCD00CECECE00CFCFCF00D0D0D000D1D1D100D2D2D200D3'
    $text &= 'D3D300D4D4D400D5D5D500D6D6D600D7D7D700D8D8D800D9D9D900DADADA00DBDBDB00DCDCDC00DDDDDD00DEDEDE00DFDFDF00E0E0E000E1E1E100E2E2E200E3E3E300E4E4E400E5E5E500'
    $text &= 'E6E6E600E7E7E700E8E8E800E9E9E900EAEAEA00EBEBEB00ECECEC00EDEDED00EEEEEE00EFEFEF00F0F0F000F1F1F100F2F2F200F3F3F300F4F4F400F5F5F500F6F6F600F7F7F700F8F8F8'
    $text &= '00F9F9F900FAFAFA00FBFBFB00FCFCFC00FDFDFD00FEFEFE00FFFFFF00E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4'
    $text &= 'E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4E4E4E4E4E4E4EAE4E4E4E4E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4C9B7B0B3A79AA2AFB2B4C1E4E4E4E4E4E4E4000000E4E4E4E4E4F0C9967E'
    $text &= '767B8187847E7C7B8BC3E4E4E4E4E4E4000000E4E4E4E4F5B08B8986888C90928F8B8B898987ACE4E4E4E4E4000000E4E4E4EDCA8C77898F94989A9B9A9898938C7889C4E4E4E4E4000000'
    $text &= 'E4E4E4CC998A8993979B9FA2A3A4A3A19C968F8C8CC1E4E4E4000000E4E4E4B9808990969DA3A7ABACADABA8A59F988C7CB6E4E4E4000000E4E4E4B2798C969BA4ACB1B6B7B8B6B4B0ABA1'
    $text &= '927FB4E4E4E4000000E4E4E4B77D8F9AA1AAB2BABEBFC1C2C1BCB4A99884B4E4E4E4000000E4E4E0A883929FA7B0BAC2CACCD0D0CDC6BDB2A18DA8EAE4E4000000E4E8BF998794A1ABB4BF'
    $text &= 'C8D3D9DDDCD7CEC4B9A7939FE4E4E4000000E4E4E0A98493A2AEB9C5CDD9E2E7E9E4DBCEBFA891AEE4E4E4000000E4E4E4B77F91A1AEBBC9D2E0EBF2F5F3E9D7C2A68BBAE4E4E4000000E4'
    $text &= 'E4E4B17A8FA0ACB9CAD8E8F4FBFDFDF3DEC4A485B5E4E4E4000000E4E4E4C18D8E98A8B6C7D7E9F6FFFFFFF8DABB9F8DBCE4E4E4000000E4E4E4DDB1928FA3B0C0CEE0EFFBFFFFEECBAB9D'
    $text &= 'A5D0E4E4E4000000E4E4E4E4D89B8596A4B6C2D1DDEBEEE7D1B2949DD1E4E4E4E4000000E4E4E4E4E4BF9E9B9BA2AABAC9D2D1C7B4A59FBCE4E4E4E4E4000000E4E4E4E4E4E4DAB698878C'
    $text &= 'A5BFBDB4B1AAAED3E4E4E4E4E4E4000000E4E4E4E4E4E4E4DFC6B6B9BCBEC6CDCFCED5E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4000000E4E4'
    $text &= 'E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4000000E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E4E40000000000'
    Return $text
EndFunc

Share this post


Link to post
Share on other sites

Nevertheless, it would be better to use imagelist. Instead of those two lines, this:

;GUICtrlSendMsg($iButton, $BM_SETIMAGE, $IMAGE_BITMAP, $bitmap_from_file)
;GUICtrlSendMsg($iButton2, $BM_SETIMAGE, $IMAGE_BITMAP, $bitmap_from_file)

$hImageList = _GUIImageList_Create(24, 24, 5, 5)
_GUIImageList_Add($hImageList, $bitmap_from_file)
_WinAPI_DeleteObject($bitmap_from_file)

_GUICtrlButton_SetImageList($iButton, $hImageList, 4)
_GUICtrlButton_SetImageList($iButton2, $hImageList, 4)

That way the result will be the same regardless of the system.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Is there a similar method available for setting the photo of a Picture control as created by GUICtrlCreatePic

or will I have to use _GDIPlus_GraphicsDrawImageRect.

At the moment, my program is reading bmp files 6 times a second to update a Pic control, which I want to avoid for obvious reasons.

The following code inserted into the above code doesn't work:

$iPic = GUICtrlCreatePic("", 10, 10, 43, 50, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUICtrlSendMsg($iPic, $BM_SETIMAGE, $IMAGE_BITMAP, $bitmap_from_file)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Is there a similar method available for setting the photo of a Picture control as created by GUICtrlCreatePic

or will I have to use _GDIPlus_GraphicsDrawImageRect.

At the moment, my program is reading bmp files 6 times a second to update a Pic control, which I want to avoid for obvious reasons.

The following code inserted into the above code doesn't work:

$iPic = GUICtrlCreatePic("", 10, 10, 43, 50, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUICtrlSendMsg($iPic, $BM_SETIMAGE, $IMAGE_BITMAP, $bitmap_from_file)

I can answer my own question. I found _SetImageBinaryToCtrl by Prog@ndy and Zedna, which does what I need.

Basically,

$imGreenLamp = imGreenLamp() ;function which contains the image in binary
_SetImageBinaryToCtrl($iPic, $imGreenLamp)
Edited by RagsRevenge

Share this post


Link to post
Share on other sites

I can answer my own question. I found _SetImageBinaryToCtrl by Prog@ndy and Zedna, which does what I need.

It's what I use and have had no problems.

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Is there a similar method available for setting the photo of a Picture control as created by GUICtrlCreatePic

or will I have to use _GDIPlus_GraphicsDrawImageRect.

At the moment, my program is reading bmp files 6 times a second to update a Pic control, which I want to avoid for obvious reasons.

The following code inserted into the above code doesn't work:

$iPic = GUICtrlCreatePic("", 10, 10, 43, 50, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUICtrlSendMsg($iPic, $BM_SETIMAGE, $IMAGE_BITMAP, $bitmap_from_file)

Look at my Resource UDF.

In sources of _SetBitmapToCtrl() you will see that message/style $BM_SETIMAGE/$BS_BITMAP is used for buttons 

and $STM_SETIMAGE/$SS_BITMAP is used for other static type of controls.

So try:

$iPic = GUICtrlCreatePic("", 10, 10, 43, 50, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $bitmap_from_file)
Edited by Zedna

Share this post


Link to post
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
Sign in to follow this  
Followers 0