Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Load JPG from memory and set it to CtrlCreatePic

$
0
0
Hi

I'm trying to set a jpg (in binary) to a ctrlPic, but by some reason the loaded picture doesn't shows up

Here how I do it (some code from other help threads):

[ autoit ]         
#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <TabConstants.au3> #include <GDIPlus.au3> #include <SendMessage.au3> #include <Memory.au3> #Region ### START Koda GUI section ### Form= Global Const $STM_SETIMAGE = 0x0172 Global $semPIC =_LoadSemPic() $Form1 = GUICreate("Form1", 158, 159, 192, 124) $Pic1 = GUICtrlCreatePic("", 8, 8, 140, 140,BitOR($GUI_SS_DEFAULT_PIC,$SS_CENTERIMAGE,$SS_BITMAP,$WS_BORDER)) $hPic1 = GUICtrlGetHandle($Pic1) _GDIPlus_Startup() _WinAPI_DeleteObject(_SendMessage($hPic1, $STM_SETIMAGE, 0, $semPIC)) _WinAPI_UpdateWindow($hPic1) _GDIPlus_Shutdown() GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _LoadSemPic() Local $bsempic = "0xFFD8FFDB0043000201010201010202020202020202030503030303030604040305070607070706070708090B0908080A0807070A" & _ "0D0A0A0B0C0C0C0C07090E0F0D0C0E0B0C0C0CFFDB004301020202030303060303060C0807080C0C0C0C0C0C0C0C0C0C0C0C0C0C" & _ "0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0CFFC0001108008C008C03012200021101" & _ "031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504" & _ "040000017D01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A16171819" Return Load_BMP_From_Mem(Binary($bsempic),True) EndFunc ;====================================================================================== ; Function Name:        Load_BMP_From_Mem ; Description:          Loads a image which is saved as a binary string and converts it to a bitmap or hbitmap ; ; Parameters:           $mem_image:     the binary string which contains any valid image which is supported by GDI+ ; Optional:                 $hHBITMAP:      if false a bitmap will be created, if true a hbitmap will be created ; ; Remark:                   hbitmap format is used generally for GUI internal images ; ; Requirement(s):       GDIPlus.au3, Memory.au3 ; Return Value(s):  Success: handle to bitmap or hbitmap, Error: 0 ; Error codes:          1: $mem_image is not a binary string ; ; Author(s):                UEZ ; Additional Code:  thanks to progandy for the MemGlobalAlloc and tVARIANT lines ; Version:                  v0.95 Build 2011-06-11 Beta ;======================================================================================= Func Load_BMP_From_Mem($mem_image, $hHBITMAP = False)     If Not IsBinary($mem_image) Then Return SetError(1, 0, 0)     Local $declared = True     If Not $ghGDIPDll Then         _GDIPlus_Startup()         $declared = False     EndIf     Local Const $memBitmap = Binary($mem_image) ;load image  saved in variable (memory) and convert it to binary     Local Const $len = BinaryLen($memBitmap) ;get length of image     Local Const $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory  ($GMEM_MOVEABLE = 0x0002)     Local Const $pData = _MemGlobalLock($hData) ;translate the handle into a pointer     Local $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     Local $hStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0)     $hStream = $hStream[3]     Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $hStream, "int*", 0) ;Creates a Bitmap object based on an IStream COM interface     $hBitmap = $hBitmap[2]     Local Const $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr")     DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, _                                            "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;release memory from $hStream to avoid memory leak     $tMem = 0     If $hHBITMAP Then         Local Const $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)         _GDIPlus_BitmapDispose($hBitmap)         If Not $declared Then _GDIPlus_Shutdown()         Return $hHBmp     EndIf     If Not $declared Then _GDIPlus_Shutdown()     Return $hBitmapEndFunc   ;==>Load_BMP_From_Mem

I think that $STM_SETIMAGE needs to be different to pic ctrl, but in help file/command list I didn't found anything

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>