Jump to content
nassausky

Load web jpg/jpeg/png into _GUIImageList

Recommended Posts

nassausky

Thanks to the help of a couple forum members I got a web png loaded onto a button.  I also want to do this with an image list. 

*Jump to the last code snippet (Slim Version) if you want to just see what I have so far.

Here is a basic example image list that works from locally stored bmp files. I would like to replace the bitmaps with jpegs or png's from the internet:

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $idListview, $hImage
    Local $sWow64 = ""
    If @AutoItX64 Then $sWow64 = "\Wow6432Node"
    Local $sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\Advanced\Images"

    GUICreate("ImageList AddBitmap", 400, 300)
    $idListview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    GUISetState(@SW_SHOW)

    ; Load images
    $hImage = _GUIImageList_Create(16, 32)
    _GUIImageList_AddBitmap($hImage, $sPath & "\Red.bmp")
    _GUICtrlListView_SetImageList($idListview, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Items", 120)

    ; Add items
    _GUICtrlListView_AddItem($idListview, "Item 1", 0)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

I tried integrating code from the working button example below that grabs a png file

#include <GDIplus.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>


_GDIPlus_Startup()
Global $myImage =        "http://icons.iconarchive.com/icons/hopstarter/soft-scraps/64/User-Administrator-Blue-icon.png"
Global $GDIbmpLarge =   _GDIPlus_BitmapCreateFromMemory(InetRead($myImage), 1) ;this is a GDI bitmap
Global $GDIplusLarge =  _GDIPlus_BitmapCreateFromHBITMAP($GDIbmpLarge) ;convert GDI to GDIPlus bitmap
Global $hGUI = GUICreate("Bitmap from inet", 540, 396, -1, -1)
GUISetBkColor(0xFFFFFF)
Global $iBtnL = GUICtrlCreateButton("", 65, 89, 72, 72, $BS_BITMAP) , $hBtnL = GUICtrlGetHandle($iBtnL)
_WinAPI_DeleteObject(_SendMessage($hBtnL, $BM_SETIMAGE, $IMAGE_BITMAP, $GDIbmpLarge)) ;this needs a GDI bitmap!!!

GUISetState()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GDIPlus_BitmapDispose($GDIplusLarge)
            _WinAPI_DeleteObject($GDIbmpLarge)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
        Case $iBtnL
            MsgBox(0, "Info", "Large Image Downloaded from web and used directly without saving to disk first!")
    EndSwitch
Until False

Here is what I tried but it doesn't work:

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GDIplus.au3> ; Needed for GDI functions

Example()

Func Example()
    Local $idListview, $hImage
    Local $sWow64 = ""
    If @AutoItX64 Then $sWow64 = "\Wow6432Node"
    Local $sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\Advanced\Images"

    GUICreate("ImageList AddBitmap", 400, 300)
    $idListview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    GUISetState(@SW_SHOW)

    ; Load images
    $hImage = _GUIImageList_Create(16, 32)
    $webImage = "http://icons.iconarchive.com/icons/hopstarter/soft-scraps/64/User-Administrator-Blue-icon.png"
    ; This line works-> _GUIImageList_AddBitmap($hImage, $sPath & "\Red.bmp")
    Global $GDIbmpLarge =   _GDIPlus_BitmapCreateFromMemory(InetRead($webImage), 1) ;this is a GDI bitmap
    Global $GDIplusLarge =  _GDIPlus_BitmapCreateFromHBITMAP($GDIbmpLarge) ;convert GDI to GDIPlus bitmap
    ; This doesn't work -> _GUIImageList_AddBitmap($hImage, _GDIPlus_BitmapCreateFromHBITMAP($GDIbmpLarge))
    ; This doesn't work -> _GUIImageList_AddBitmap($hImage, _GDIPlus_BitmapCreateFromHBITMAP($GDIplusLarge))

    _GUICtrlListView_SetImageList($idListview, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Items", 120)

    ; Add items
    _GUICtrlListView_AddItem($idListview, "Item 1", 0)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

*Slim version (No comments)

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GDIplus.au3> 

Example()

Func Example()
    Local $idListview, $hImage

    GUICreate("ImageList AddBitmap", 400, 300)
    $idListview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    GUISetState(@SW_SHOW)

    ; Load images
    $hImage = _GUIImageList_Create(16, 32)
    $webImage = "http://icons.iconarchive.com/icons/hopstarter/soft-scraps/64/User-Administrator-Blue-icon.png"
    Global $GDIbmpLarge =   _GDIPlus_BitmapCreateFromMemory(InetRead($webImage), 1) ;this is a GDI bitmap
    Global $GDIplusLarge =  _GDIPlus_BitmapCreateFromHBITMAP($GDIbmpLarge) ;convert GDI to GDIPlus bitmap
    ; This doesn't work -> _GUIImageList_AddBitmap($hImage, _GDIPlus_BitmapCreateFromHBITMAP($GDIplusLarge))

    _GUICtrlListView_SetImageList($idListview, $hImage, 1)
    _GUICtrlListView_AddColumn($idListview, "Items", 120)
    _GUICtrlListView_AddItem($idListview, "Item 1", 0)

    Do
      Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc
Edited by nassausky

Share this post


Link to post
Share on other sites
UEZ

You must start GDI+ before you use any function from GDI+ and don't forget to cleanup the resources!

Try this:

 

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GDIplus.au3> ; Needed for GDI functions

Example()

Func Example()
    _GDIPlus_Startup()
    Local $idListview, $hImage

    GUICreate("ImageList AddBitmap", 400, 300)
    $idListview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    GUISetState(@SW_SHOW)

    ; Load images
    $hImage = _GUIImageList_Create(32, 32)
    $webImage = "http://icons.iconarchive.com/icons/hopstarter/soft-scraps/64/User-Administrator-Blue-icon.png"
    ; This line works-> _GUIImageList_AddBitmap($hImage, $sPath & "\Red.bmp")
    Global $GDIpBmpLarge = _GDIPlus_BitmapCreateFromMemory(InetRead($webImage)) ;GDI+ image!
    Global $GDIpBmpResized = _GDIPlus_ImageResize($GDIpBmpLarge, 32,32) ;GDI+ image
    Global $GDIbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($GDIpBmpResized) ;GDI image!

    _GUIImageList_Add($hImage, $GDIbmp)
    _GUICtrlListView_SetImageList($idListview, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Items", 120)

    ; Add items
    _GUICtrlListView_AddItem($idListview, "Item 1", 0)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ;cleanup resources
    _GDIPlus_BitmapDispose($GDIpBmpLarge)
    _GDIPlus_BitmapDispose($GDIpBmpResized)
    _WinAPI_DeleteObject($GDIbmp)
    _GDIPlus_Shutdown()
    GUIDelete()
EndFunc   ;==>Example
 

 

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
nassausky

That is great such a simple problem to initialize and I can't forget to cleanup.  I am a bit confused now about gdi and gdi+.

This is a piece of  your current code above from this topic:

[code A]

Global $GDIpBmpLarge = _GDIPlus_BitmapCreateFromMemory(InetRead($webImage)) ;GDI+ image!
    Global $GDIpBmpResized = _GDIPlus_ImageResize($GDIpBmpLarge, 32,32) ;GDI+ image
    Global $GDIbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($GDIpBmpResized) ;GDI image!

The below code is a piece from my initial topic with creating images on buttons from ()

[code B]

Global $hHBitmapL = _GDIPlus_BitmapCreateFromMemory(InetRead($webImage), 1) ;this is a GDI bitmap
Global $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmapL) ;convert GDI to GDIPlus bitmap
Global $hBitmapM = _GDIPlus_ImageResize($hBmp,25,25) ;this is a GDIPlus bitmap!
Global $hHBitmapM = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmapM) ;this is a GDI bitmap

The first 2 lines of CODE B says _GDIPlus_BitmapCreateFromMemory creates just a GDI but CODE A says it creates a GDI+.

Another thing that confused me is that in CODE A you resized on line to immediately whatever came out of memory but on CODE B you resized it after converting from hBitmap.

I am so confused. How can I tell which comments are typos.

Thanks for your patience!

Share this post


Link to post
Share on other sites
UEZ

Just check out the 2nd parameter from the function _GDIPlus_BitmapCreateFromMemory! -> _GDIPlus_BitmapCreateFromMemory ( $dImage [, $bHBITMAP = False] )

$bHBITMAP

[optional] If False a bitmap will be created, if True a hbitmap (GDI) will be created

 

If false then GDIPlus else GDI image!

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
nassausky

Thanks very much.  It looks like I just have to remember

GDI = hbitmap

and

GDIplus = bitmap

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

  • Similar Content

    • odaylton
      By odaylton
      Hello everyone ,
      Text translated from Portuguese by google - please apologize for any errors

      Once again I need a light from the gurus of this wonderful website
      I am fanatic by combobox for its usability but I am not able to uncertain images within lists ...
      I know uncertain icons, and cursors but I am not able to insert gif or jpg images.
      1) How to solve this ...
      2) will the path is to convert gif into bmp and then uncertain ... how to do that?
      #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> ;dados de mouse #include <WinAPIRes.au3> ;COMBO #include <GuiComboBoxEx.au3> ;Fonts #include <FontConstants.au3> ;obter imagem de arquivo #include <GDIPlus.au3> #include <WinAPIGdi.au3> Example() Func Example() Local $hGUI, $hImage, $hCombo, $hFont Local $idListview, $hImage Local $sWow64 = "" Local $Pasta = "C:\WINDOWS\Cursors\3dgarro.cur" Local $PastaROMs = @MyDocumentsDir & "\Stella\ROMs\" ;com barra no final $hGUI = GUICreate("ImageList", 500, 310) GUISetFont(14, 400, 0, "Arial") ;<<<<<<<<<<this does not work for _GUICtrlComboBoxEx_Create $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 494, 200) ;GUICtrlSetFont($hCombo, 14, 400, 0, "Arial");<<<<<<<<<<It does not work ; ;Create a handle to a font object $hFont = _WinAPI_CreateFont(30, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial') ;Pass the handle to _WinAPI_SetFont _WinAPI_SetFont($hCombo, $hFont) $idListview = GUICtrlCreateListView("", 2, 50, 494, 250, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)) GUISetState(@SW_SHOW) ; Initialize GDI+ library _GDIPlus_Startup() ; Load images $hImage = _GUIImageList_Create(120, 70, 6, 2) ;32,32,5,5) ; $DadosCombo = "Escolha|" & _GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x0000FF, 120, 70)) ;Local $aCursors[] = [32650, 32512, 32515, 32649, 32651, 32513, 32648, 32646, 32643, 32645, 32642, 32644, 32516, 32514] For $i = 1 To 10 $sFile = FileOpenDialog("Please select an image", $PastaROMs, "Image (*.jpg;*.png;*.bmp;*.gif;*.tif)", BitOR($FD_PATHMUSTEXIST, $FD_FILEMUSTEXIST)) If @error Then Exit MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "No image file has been selected", 30) $a = _GDIPlus_BitmapCreateFromFile ($sFile);<<<<< ok If @error Or Not $hImage Then MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file isn't supported by GDIPlus!") Else $b=_GUIImageList_Add($hImage, $a);<<<<<< Return -1 $DadosCombo &= "|" & $i & "_img_princ.gif""|" & $b EndIf Next _GUICtrlListView_SetImageList($idListview, $hImage, 1) _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage) ; Add columns _GUICtrlListView_AddColumn($idListview, "Icons - Mouses", 350) ; Add items $a = StringSplit($DadosCombo, "|") For $i = 1 To $a[0] Step 2 _GUICtrlListView_AddItem($idListview, $a[$i], $a[$i + 1]) _GUICtrlComboBoxEx_AddString($hCombo, $a[$i], $a[$i + 1], $a[$i + 1]) Next ;AutoIt_Debugger_Command:Disable_Debug ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() ;AutoIt_Debugger_Command:Enable_Debug EndFunc ;==>Example tks
    • Xandy
      By Xandy
      MapIt is a tile world editor.  MapIt was built around the concept of reversing Dragon Warrior map images.  MapIt can take image input and produce a tile and world array.
      MapIt features Unity style dragable labels that adjust property values.

      MapParser is a C++ project that scans images for unique tiles.  MapParser is very fast.  Due to hard drive failure, many bugs were restored b/c I had to rewind many years.  Frustrated with the design, I wrote a new version from the ground up.  This New Version:  AutoIt Front-end, command line controls, and shared with the world; so that I can't lose it again.
      You can toggle the C++ MapParser off to see the difference in speeds between the MapParser CPP verse AutoIt function.  Function is named Scan_Tiles() in AutoIt.  You can also chose to download without MapParser.exe.
      At the moment Scanning a image resets the arrays, but you can add tiles after scanning.
      Images can be added as tiles without scan image at all.  Then configure settings to give your world parameters and manually fill the world data with tile indexes.
      Using the settings you can change tile size after a scan.  Example: you wanted to replace a map with different sized tiles.
      Changing and replacing tile / world data is easy.  B/c tile world editor.

      Hotkeys, I use CTRL+R in image above to signal replace tile action and I use "G" to Get the tile under mouse.
      Hotkeys are not saved to disk and thus are set to default between sessions.
      I might draw the world to pre-rendered surfaces and use them as multi-layer someday.  I do that in my AutoIt, DragonWarrior Remake but I could spend forever unsure what features are important for this.  The DW_Remake has a method of replacing a tile with a tile on two layers.  So you could replace a tree on the first layer with a grass, and a tree in the second layer.  This is all getting very confusing.
      I attempted to write the good code.  If something could be better, please advise.
      Fifth release.  Enjoy.
      For download, videos, and example of created world file data; please visit the MapIt webpage: http://songersoft.com/programming/mapit/mapit_about.phtml
      Special thanks: @AdmiralAlkex, @Melba23, @MrCreatoR
      Main AutoIt source file: Will not run without other Includes and SDL DLLs.
      Last Update: 5/26/2018 3:45 PM EST
      REMOVED CODE BLOCK:  I was informed the this page loaded very slowly, one solution so far has been to remove the 2k lines in the code block.
      When I recieve more feedback from the User I may reduce image size or remove images.
      Next Version Added: $eSETTING_TILE_LAST_PATH I have the weekend, I want to write world layers with aBoard surfaces.  
    • 31290
      By 31290
      Hi everyone, hope you are doing fine
      Well, I'm currently writing a small script that goes to a certain web page, finds the first link of a specified section and download the file associated to this link.
      Depending on the computer that the tool is launched, the script gets the computer model and search in the (provided here) ini file which link to follow.
      At first, Dell was kind enough to provide only one link but now, they provide two of them. The first one is now a .txt file (  ) whereas my script has been designed to download only the fist and latest link released for the BIOS Update.

      Here's the current code which is working with only the first and latest link of the BIOS category:
      So the question is: 
      In the case of double links like shown in the picture above, how it is possible to tell the script to download only the link containing an the .exe file?
      Of course, I could have changed the array result to [1] instead of [0] [which is working] but it seems that Dell does that randomly and that I deal with a lot of computer models.
      Thanks for the help you can provide, 
      -31290-
       
      SEE_BIOS_LINKS.ini
    • lenclstr746
      By lenclstr746
      HELLO GUYS
      I'm a work on a background see and click bot project 
      I can complete it if your help me
      (using imagesearch , gdi+ and  fastfind)
    • dadalt95
      By dadalt95
      I would like to know if it's possible to pass an image recognition (captcha) system.
       
      What are the ways to achieve this?
      Just the references or links is enough for me by now.
       
      Thanks by now!
       
      Thanks!
×