Jump to content

[SOLVED] _SetImageBinaryToCtrl() - Retrieving Image from the Internet


guinness
 Share

Recommended Posts

So I am using by ProgAndy and it seems this weird problem is constant throughout. I have also used by Deathbringer (loosely based on the same code) and the problem is still visible.

The Problem Was: When the GUI is minimised the image resizes upon repainting. But if you uncomment line 11 and comment 12 you will see the image is loaded correctly and is still the correct dimension when minimised. Why would this be? Isn't it the same thing, just binary data or am I missing something? If anyone knows that would be highly appreciated.

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Memory.au3>
#include <WinAPI.au3>

#Region - GUI Create
GUICreate('Image from Stream smile.gif', 200, 80, -1, -1)
;#~ Start image Creation
$picbox = GUICtrlCreatePic("", 10, 10, 465, 100) ; <<<<< Set Size and it will resize to the correct dimensions.
GUICtrlSetCursor(-1, 0)
;~ $LOGO = _LOGOBin() ; <<<<< This will grab the Binary Code from the Function _LOGOBin()
$LOGO = _INetBinaryImage() ; <<<<< This will grab the Binary Code from the Function _INetBinaryImage() by using InetRead() to Return in Binary.
_SetImageBinaryToCtrl($picbox, $LOGO)
;#~ end image Creation
GUICtrlCreateLabel("www.progandy.de.tt", 80, 20)
$zedna = GUICtrlCreateLabel("Zedna on autoitscript.com", 80, 40)
GUICtrlSetCursor(-1, 0)

GUISetState()
#EndRegion - GUI Create


#Region - GUI SelectLoop
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $picbox
            ShellExecute("www.progandy.de.tt")
        Case $msg = $zedna
            ShellExecute("http://www.autoitscript.com/forum/index.php?showuser=6483")
    EndSelect
WEnd
#EndRegion - GUI SelectLoop

Func _INetBinaryImage($sImage = "http://www.autoitscript.com/forum/public/style_images/autoit/logo.png")
    $sImage = InetRead($sImage)
    If @error Then Return SetError(1, 1, -1)
    Return $sImage
EndFunc   ;==>_INetBinaryImage

Func _LOGOBin()
    Local $FileName = "0xFFD8FFE000104A46494600010101006000600000FFE1001645786966000049492A0008000000000000000000FFDB004300080606070605080707070909080A"
    $FileName &= "0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720222C231C1C2837292C30313434341F27393D38323C2E333432FFDB0043010909090C0B0C180D0D"
    $FileName &= "1832211C213232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232FFC0001108003F0040"
    $FileName &= "03012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D"
    $FileName &= "01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A43444546474849"
    $FileName &= "4A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5"
    $FileName &= "C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708"
    $FileName &= "090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434"
    $FileName &= "E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A9293949596"
    $FileName &= "9798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C0301"
    $FileName &= "0002110311003F00F78DDC64D729ABF8BFEC17DF678EDE699B04E2242C703D80F7AE9657DB1393D00AE37C29FE97E30D62F32D886148978E097624FE5B17F3AF"
    $FileName &= "0B30E7AF8B8616326935776FC0EFC2538724EACD5D4509FF0009CCFF00F40CBFFF00C077FF000A07C418609116EE196DF79C2F9CA5371F6CF5AED26B88EDE332"
    $FileName &= "CD2A471AFDE791B007E2698925BDEDBEE4314F04808C821D5877E7A1A1E4CD7C35A57F52BEB343AD1D3D59574CD6ADB5240617539E7835A7BABCF759D363F0CE"
    $FileName &= "B3697DA78F2ED2EA429242B9DA8FD723B007D3B62B7B53F14DB68ED6AB7322A89D495C9C1E3AFF003ACE19855C1D4950C4FBD6D9ADC2AE0D4F96543552FBCE93"
    $FileName &= "26973EF58963E23B1BE00472A96EBD6B5C3E4023A1AF530B8FA189FE1BD7B1C5528CE93E59AB14AFE51158CAE4FF0009EB5CE780A33FD9B7D78C4E6E6E98807D"
    $FileName &= "1405AD0F13DC791A248DBB048A3C2D07D93C316119565668C48CA7A82DC915C186FDEE67567FCA923B57B9817FDE7F912F8934B9F5AD20D9413C7096914B1917"
    $FileName &= "20A8392314BE1ED1D740D256C84C653E63485F18E49CE00EC2A8EBBE25974AD4A0B1B6B2FB54D2446565DFB768CE07F5FCAB34F897C4374A63B7D262818E30F2"
    $FileName &= "316C7AF15D75B1B84A355BA92B4874B0D89A941434507AEE897C6D73E7DC69BA544D995A6F39D476400807F13FC8D5CD575CB7D2960B3BBD365BC89E2FDE9455"
    $FileName &= "70BDB1B5BAE6A9E99A47F6619F59D6EE8BCA17749349D71E83F4C0141D2F45F165F3EA16D7F72D1A9D93440B2678F978600AF1F9D7954A55B158A788A4924B45"
    $FileName &= "7EBDCE9B518C6309DDC637BB5DD95DB45D175DB77BDF0D4B1D9DF47FF2C946C5CE3EEB20E83B640FCEB47C2FAD4B705EC6F55E2BA84EC747EA0FF9FC2B92568B"
    $FileName &= "C3DE35DD64EE208A68EDA42E4B16DD8C8CFD4823E95D0EB2A2CFC71652C7F29B984EF007F75B00FE4696323FBB78986938357B7537AB4AE952936E32578DF75E"
    $FileName &= "44BE3AF35F4A448E36656E084EB8EF491F8D34C8618E34B5D480450A33067B7FBD5D21F2DD364881D7B66A3FB2D9FF00CFBA9F6AD961F1F86AB51D049A93BEE7"
    $FileName &= "9D0C4D074634EAC5E9E76392B0B93AEF8C9EF9229D2DD2258E31326D23B9F5EE6ACEADE21BEB2F16C3A6431C696ECF17CE63C9756C86FD476AD2D76EA6D22C05"
    $FileName &= "C69B6F197C82491FC3DC63D6B175FD3FFE128D32CF58D20FFA4AAE55720332F5DB9E9B95B18CFA9F5AE5C35275E756A54B3A975A5B6B1DB4E54EA4A329AB536B"
    $FileName &= "955DECFCCB1E3B9716BA7248C040D724C99E9F2A9229FE0780269771A9C9841772EF5623198C7DD3F4EB8F635969E398E583ECFA9E9624B98DB0E8CC000C3D55"
    $FileName &= "F907F95476FE3AB9B69E492F2DE17B565022821700C78FE79FD31C57A4AAE1A388559CBA5AD6D8D3EAB89FAAFB050D9EF75AFA143C3D04BE22D623B8F2CBC1F6"
    $FileName &= "937770EC721792513DCF41EC0574334DFDB3E39022F9A1B15F2B781D589CB0FC38AA5A8EBDAA7F621974ED29F4BD39884F3D940701BBAA81C0E8371F5AE83C2F"
    $FileName &= "A759E9FA6AC96E779719DDEA7D4D7062D592C253D5D4776F61D7AAE29D79AB69CA92D6DDEE69EEA37549F64B8FF9E47FEFA1FE349F64B8FF009E47FEFA1FE35F"
    $FileName &= "507CE0D611CD118661943EA3A572B2691AAF87EE64B8D25849048774903728DEFEC7DC7E39E2BADFB25C8FF9647FEFA1FE34E586ED78F2C91E8483FD6BC9C5E5"
    $FileName &= "CE753DBD0972CFF067561F172A49C5ABA7D0E324F10D9DC129AC6812E4F0488D6507078F7E94D8B5BD16CCE74DD0253213CE2D82631D0E4D766D661C1F32C816"
    $FileName &= "F5C8FF001A45B054E63B200FD56B99ACCF6718B7DCEB58BC35BE17E977638E921D7BC4E0C37282CEC5FAC49C961FED377EDD2BAAB5B48EC2C92D636CEDEBED56"
    $FileName &= "DA2BB23023DA3D148FF1A8FECB71FF003C8FFDF43FC6B7C365F515555F152BC96DD91CF88C5BA9154E2B963D91FFD9"
    Return $FileName
EndFunc   ;==>_LOGOBin

;Authors: Prog@ndy, based on code by Zedna
Func _SetImageBinaryToCtrl($CtrlId, ByRef $Binary)
    Local $picdata = Binary($Binary) ; Fetch the Data
    Local $piclength = BinaryLen($picdata) ; Get Length

    Local $picstruct = DllStructCreate("byte[" & $piclength & "]")
    DllStructSetData($picstruct, 1, $picdata)
    Local $picmemory = DllStructGetPtr($picstruct)
    _SetMemoryImageToCtrl($CtrlId, $picmemory, $piclength)
    DllStructSetData($picstruct, 1, 0)
    $picstruct = ""
EndFunc   ;==>_SetImageBinaryToCtrl

; Authors: Zedna, based on code by Prog@ndy
Func _SetMemoryImageToCtrl($CtrlId, $Pointer, $nSize)
    Local $hData, $pData, $pStream, $pBitmap, $hBitmap
    ; use GDI+ for converting to bitmap first
    $hData = _MemGlobalAlloc($nSize, 2)
    $pData = _MemGlobalLock($hData)
    _MemMoveMemory($Pointer, $pData, $nSize)
    _MemGlobalUnlock($hData)
    $pStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "int", $hData, "long", 1, "Int*", 0)
    $pStream = $pStream[3]
    _GDIPlus_Startup()
    $pBitmap = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0)
    $pBitmap = $pBitmap[2]
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
    _SetBitmapToCtrl($CtrlId, $hBitmap)
    If @error Then SetError(3, 0, 0)
    _GDIPlus_BitmapDispose($pBitmap)
    _GDIPlus_Shutdown()
    _WinAPI_DeleteObject($pStream)
    _MemGlobalFree($hData)
EndFunc   ;==>_SetMemoryImageToCtrl

; internal helper function
; Out of resources.au3 :)
Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)
    ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE)
    If @error Then Return SetError(2, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(3, 0, 0)
    Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc   ;==>_SetBitmapToCtrl
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_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: 22/04/2018

Link to comment
Share on other sites

:x What an Idiot! I didn't even think to try that. It is weird though that when the Binary is in the AU3 File it doesn't matter about the Size. But thanks Deathbringer. I didn't add your name to the initial post because I expected your help, simply giving users the chance to discover your code. Updated OP.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_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: 22/04/2018

Link to comment
Share on other sites

Try this:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Memory.au3>
#include <WinAPI.au3>

_GDIPlus_Startup()
$LOGO = _INetBinaryImage() ; <<<<< This will grab the Binary Code from the Function _INetBinaryImage() by using InetRead() to Return in Binary.
$hImage = Load_BMP_From_Mem($LOGO)
$iWidth = _GDIPlus_ImageGetWidth($hImage)
$iHeight = _GDIPlus_ImageGetHeight($hImage)

#Region - GUI Create
GUICreate('Image from Stream smile.gif', 200, 80, -1, -1)
;#~ Start image Creation
$picbox = GUICtrlCreatePic("", 10, 10, $iWidth, $iHeight)
GUICtrlSetCursor(-1, 0)
;~ $LOGO = _LOGOBin() ; <<<<< This will grab the Binary Code from the Function _LOGOBin()

_SetImageBinaryToCtrl($picbox, $LOGO)
;#~ end image Creation
GUICtrlCreateLabel("www.progandy.de.tt", 80, 20)
$zedna = GUICtrlCreateLabel("Zedna on autoitscript.com", 80, 40)
GUICtrlSetCursor(-1, 0)

GUISetState()
#EndRegion - GUI Create


#Region - GUI SelectLoop
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_Shutdown()
            Exit
        Case $msg = $picbox
            ShellExecute("www.progandy.de.tt")
        Case $msg = $zedna
            ShellExecute("http://www.autoitscript.com/forum/index.php?showuser=6483")
    EndSelect
WEnd
#EndRegion - GUI SelectLoop

Func _INetBinaryImage($sImage = "http://www.autoitscript.com/forum/public/style_images/autoit/logo.png")
    $sImage = InetRead($sImage)
    If @error Then Return SetError(1, 1, -1)
    Return $sImage
EndFunc   ;==>_INetBinaryImage

Func _LOGOBin()
    Local $FileName = "0xFFD8FFE000104A46494600010101006000600000FFE1001645786966000049492A0008000000000000000000FFDB004300080606070605080707070909080A"
    $FileName &= "0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720222C231C1C2837292C30313434341F27393D38323C2E333432FFDB0043010909090C0B0C180D0D"
    $FileName &= "1832211C213232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232FFC0001108003F0040"
    $FileName &= "03012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D"
    $FileName &= "01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A43444546474849"
    $FileName &= "4A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5"
    $FileName &= "C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708"
    $FileName &= "090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434"
    $FileName &= "E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A9293949596"
    $FileName &= "9798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C0301"
    $FileName &= "0002110311003F00F78DDC64D729ABF8BFEC17DF678EDE699B04E2242C703D80F7AE9657DB1393D00AE37C29FE97E30D62F32D886148978E097624FE5B17F3AF"
    $FileName &= "0B30E7AF8B8616326935776FC0EFC2538724EACD5D4509FF0009CCFF00F40CBFFF00C077FF000A07C418609116EE196DF79C2F9CA5371F6CF5AED26B88EDE332"
    $FileName &= "CD2A471AFDE791B007E2698925BDEDBEE4314F04808C821D5877E7A1A1E4CD7C35A57F52BEB343AD1D3D59574CD6ADB5240617539E7835A7BABCF759D363F0CE"
    $FileName &= "B3697DA78F2ED2EA429242B9DA8FD723B007D3B62B7B53F14DB68ED6AB7322A89D495C9C1E3AFF003ACE19855C1D4950C4FBD6D9ADC2AE0D4F96543552FBCE93"
    $FileName &= "26973EF58963E23B1BE00472A96EBD6B5C3E4023A1AF530B8FA189FE1BD7B1C5528CE93E59AB14AFE51158CAE4FF0009EB5CE780A33FD9B7D78C4E6E6E98807D"
    $FileName &= "1405AD0F13DC791A248DBB048A3C2D07D93C316119565668C48CA7A82DC915C186FDEE67567FCA923B57B9817FDE7F912F8934B9F5AD20D9413C7096914B1917"
    $FileName &= "20A8392314BE1ED1D740D256C84C653E63485F18E49CE00EC2A8EBBE25974AD4A0B1B6B2FB54D2446565DFB768CE07F5FCAB34F897C4374A63B7D262818E30F2"
    $FileName &= "316C7AF15D75B1B84A355BA92B4874B0D89A941434507AEE897C6D73E7DC69BA544D995A6F39D476400807F13FC8D5CD575CB7D2960B3BBD365BC89E2FDE9455"
    $FileName &= "70BDB1B5BAE6A9E99A47F6619F59D6EE8BCA17749349D71E83F4C0141D2F45F165F3EA16D7F72D1A9D93440B2678F978600AF1F9D7954A55B158A788A4924B45"
    $FileName &= "7EBDCE9B518C6309DDC637BB5DD95DB45D175DB77BDF0D4B1D9DF47FF2C946C5CE3EEB20E83B640FCEB47C2FAD4B705EC6F55E2BA84EC747EA0FF9FC2B92568B"
    $FileName &= "C3DE35DD64EE208A68EDA42E4B16DD8C8CFD4823E95D0EB2A2CFC71652C7F29B984EF007F75B00FE4696323FBB78986938357B7537AB4AE952936E32578DF75E"
    $FileName &= "44BE3AF35F4A448E36656E084EB8EF491F8D34C8618E34B5D480450A33067B7FBD5D21F2DD364881D7B66A3FB2D9FF00CFBA9F6AD961F1F86AB51D049A93BEE7"
    $FileName &= "9D0C4D074634EAC5E9E76392B0B93AEF8C9EF9229D2DD2258E31326D23B9F5EE6ACEADE21BEB2F16C3A6431C696ECF17CE63C9756C86FD476AD2D76EA6D22C05"
    $FileName &= "C69B6F197C82491FC3DC63D6B175FD3FFE128D32CF58D20FFA4AAE55720332F5DB9E9B95B18CFA9F5AE5C35275E756A54B3A975A5B6B1DB4E54EA4A329AB536B"
    $FileName &= "955DECFCCB1E3B9716BA7248C040D724C99E9F2A9229FE0780269771A9C9841772EF5623198C7DD3F4EB8F635969E398E583ECFA9E9624B98DB0E8CC000C3D55"
    $FileName &= "F907F95476FE3AB9B69E492F2DE17B565022821700C78FE79FD31C57A4AAE1A388559CBA5AD6D8D3EAB89FAAFB050D9EF75AFA143C3D04BE22D623B8F2CBC1F6"
    $FileName &= "937770EC721792513DCF41EC0574334DFDB3E39022F9A1B15F2B781D589CB0FC38AA5A8EBDAA7F621974ED29F4BD39884F3D940701BBAA81C0E8371F5AE83C2F"
    $FileName &= "A759E9FA6AC96E779719DDEA7D4D7062D592C253D5D4776F61D7AAE29D79AB69CA92D6DDEE69EEA37549F64B8FF9E47FEFA1FE349F64B8FF009E47FEFA1FE35F"
    $FileName &= "507CE0D611CD118661943EA3A572B2691AAF87EE64B8D25849048774903728DEFEC7DC7E39E2BADFB25C8FF9647FEFA1FE34E586ED78F2C91E8483FD6BC9C5E5"
    $FileName &= "CE753DBD0972CFF067561F172A49C5ABA7D0E324F10D9DC129AC6812E4F0488D6507078F7E94D8B5BD16CCE74DD0253213CE2D82631D0E4D766D661C1F32C816"
    $FileName &= "F5C8FF001A45B054E63B200FD56B99ACCF6718B7DCEB58BC35BE17E977638E921D7BC4E0C37282CEC5FAC49C961FED377EDD2BAAB5B48EC2C92D636CEDEBED56"
    $FileName &= "DA2BB23023DA3D148FF1A8FECB71FF003C8FFDF43FC6B7C365F515555F152BC96DD91CF88C5BA9154E2B963D91FFD9"
    Return $FileName
EndFunc   ;==>_LOGOBin

;Authors: Prog@ndy, based on code by Zedna
Func _SetImageBinaryToCtrl($CtrlId, ByRef $Binary)
    Local $picdata = Binary($Binary) ; Fetch the Data
    Local $piclength = BinaryLen($picdata) ; Get Length

    Local $picstruct = DllStructCreate("byte[" & $piclength & "]")
    DllStructSetData($picstruct, 1, $picdata)
    Local $picmemory = DllStructGetPtr($picstruct)
    _SetMemoryImageToCtrl($CtrlId, $picmemory, $piclength)
    DllStructSetData($picstruct, 1, 0)
    $picstruct = ""
EndFunc   ;==>_SetImageBinaryToCtrl

; Authors: Zedna, based on code by Prog@ndy
Func _SetMemoryImageToCtrl($CtrlId, $Pointer, $nSize)
    Local $hData, $pData, $pStream, $pBitmap, $hBitmap
    ; use GDI+ for converting to bitmap first
    $hData = _MemGlobalAlloc($nSize, 2)
    $pData = _MemGlobalLock($hData)
    _MemMoveMemory($Pointer, $pData, $nSize)
    _MemGlobalUnlock($hData)
    $pStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "int", $hData, "long", 1, "Int*", 0)
    $pStream = $pStream[3]
    _GDIPlus_Startup()
    $pBitmap = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0)
    $pBitmap = $pBitmap[2]
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
    _SetBitmapToCtrl($CtrlId, $hBitmap)
    If @error Then SetError(3, 0, 0)
    _GDIPlus_BitmapDispose($pBitmap)
    _GDIPlus_Shutdown()
    _WinAPI_DeleteObject($pStream)
    _MemGlobalFree($hData)
EndFunc   ;==>_SetMemoryImageToCtrl

; internal helper function
; Out of resources.au3 :)
Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)
    ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE)
    If @error Then Return SetError(2, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(3, 0, 0)
    Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc   ;==>_SetBitmapToCtrl

;======================================================================================
; 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) ;not working properly
    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 $hBitmap
EndFunc   ;==>Load_BMP_From_Mem

Br,

UEZ

Edited by UEZ

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 you beat me to it, I was just adding _GDIPlus_ImageGetWidth($hImage) & _GDIPlus_ImageGetHeight($hImage) to the example and using ControlMove, but it kept crashing, so your way seems a lot better :x

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_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: 22/04/2018

Link to comment
Share on other sites

  • 8 months later...

What do you mean exactly? The conversation of myimage.png to a binary string?

Br,

UEZ

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

here is my effort, there are others out there, as in the reply to that thread from guiness referencing UEZs

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

In the example the image is gotten from the internet. I have a file on my hard disk named 'myimage.png'. I would like to display it in a Picture control .

The example looked like a way to do that but I'm not familiar enough with GDP+ and the other graphics support to make the modification from the example to what I wish to do, display a .png file in a Picture control or any other control.

Any help would be greatly appreciated.

Regards,

Jim

Link to comment
Share on other sites

It is easy. Just replace

$hImage = Load_BMP_From_Mem($LOGO)

with

$hImage =_GDIPlus_ImageLoadFromFile("myimage.png")

Probably you have to set the path to myimage.png properly.

Br,

UEZ

PS: above text is BULLSHIT - ignore it!

Edited by UEZ

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

I tried the change you suggested and I still get the picture from the Internet in the picture area with the two labels on top. I noticed that $LOGO is still gotten from the Internet and that the line

_SetImageBinaryToCtrl($picbox, $LOGO)

still references the image from the Internet and that is what is displayed.

I tried changing $LOGO to $hImage in that line and got a gray picture area.

I also verified that the image file exists and is a valid .png file by loading it into MS Paint from the location I used.

Could I trouble you to give me some additional help?

Regards,

Jim

Edited by obrienj
Link to comment
Share on other sites

obrienj, I'm sorry that I told bullshit in my previous post! :graduated:

When you replace it with $hImage =_GDIPlus_ImageLoadFromFile("myimage.png") it will get only the dimension of your image - nothing more.

Try this instead:

;coded by UEZ 2011
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
 
Global Const $IMAGE_BITMAP = 0
Global Const $STM_SETIMAGE = 0x0172
Global $msg
Global Const $hGUI = GUICreate("Test", 600, 250)
Global Const $idLogo = GUICtrlCreatePic("", 215, 20, 169, 68)
Global Const $idButton = GUICtrlCreateButton("", 266, 150, 78 , 81, $BS_BITMAP)
Global Const $hButton = GUICtrlGetHandle($idButton)
 
_GDIPlus_Startup()
Global Const $path = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir")
Global Const $Img_Logo = _GDIPlus_ImageLoadFromFile($path & "\Examples\GUI\logo4.gif") ;_GDIPlus_ImageLoadFromFile("myimage.png")
Global Const $Bmp_Logo = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Img_Logo)
_WinAPI_DeleteObject(GUICtrlSendMsg($idLogo, $STM_SETIMAGE, $IMAGE_BITMAP, $Bmp_Logo))
Global Const $Img_Button = _GDIPlus_ImageLoadFromFile($path & "\Examples\GUI\merlin.gif")
Global Const $Bmp_Button = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Img_Button)
_WinAPI_DeleteObject(_SendMessage($hButton, $BM_SETIMAGE, $IMAGE_BITMAP, $Bmp_Button))
_WinAPI_UpdateWindow($hButton)
GUISetState()
 
While True
    $msg = GUIGetMsg()
    Switch $msg
        Case $idLogo
            MsgBox(0, "Information", "Image was clicked!")
        Case $idButton
            MsgBox(0, "Information", "Button was clicked!")
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($Bmp_Logo)
            _WinAPI_DeleteObject($Bmp_Button)
            _GDIPlus_ImageDispose($Img_Button)
            _GDIPlus_ImageDispose($Img_Logo)
            _GDIPlus_Shutdown()
            GUIDelete($hGUI)
            Exit
    EndSwitch
WEnd

Sometimes I've some brain outages...

Br,

UEZ

Edit: backslashes were gone.

Edited by UEZ

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

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