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

    • Xandy
      By Xandy
      Special thanks: AdmiralAlkex, Melba23, MrCrearoR, Dragon Warrior 3
      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.  
      Changing and replacing tile / world data is easy.  B/c tile world editor.

      CTRL+R in image above to signal replace tile action and I use "G" to Get the tile under mouse.
      A full list of hotkeys can be assigned in the: Help Menu\Hotkeys
       
      MapParser is a C++ project that scans images for unique tiles. 
      MapIt can be downloaded without MapParser. MapParser can be toggled off in the Scan_Image_Dialog. Without MapParser, MapIt will use the Scan_Tiles() function written in AutoIt ; which is 100 * slower Idk. If MapParser.exe will not run for you:      Installing Visual C++ Redistributable for Visual Studio 2015 should fix it: https://www.microsoft.com/en-us/download/details.aspx?id=48145   
      You can start with example world and tiles.
      Example world was made following these steps:
      Started with a tile map image of DragonWarrior3 town of: Reeve Using the Scan_Image dialog, I set the area to exclude the key legend to the far right of image. After scanning the map image to world and tile array.  I removed a few of the map artifacts.  More work could be done on this world; removing unwanted tiles, but it is fine for now. I saved my world to disk.  This creates folder: Worldname: Containing folder of Tiles and a Worldname.txt. Using The Gimp, I edited some tiles to have a transparent color: Stairs, Trees, Desk Tables, Chest-of-drawers, chairs, Signs, Doors, Beds. I changed the world layers to 2: Help Menu \ Settings \ eSETTING_WORLD_L = 2 F9 Finds all selected tile on current layer and changes to a new selected tile on new layer. I used F9 to change all Trees on layer: 0 to Trees on layer: 1. Then I used F9 to change all Trees on layer: 0 to Grass on layer: 0  
      In this video you can see how I used the Tile Menu \ Replace From Disk option to remap tile images to my custom tiles.  Conveniently my tiles already have a transparent pixel.
      See video for how that was done:
      To use the example world:
      First unzip the world save file: http://songersoft.com/programming/mapit/worlds/Reeve_Swapped.zip From the World Menu: choose \Load Navigate to the Reeve_Swapped.txt located in the extracted zip. Or you can scan any image.
      The map images I used are here: http://www.realmofdarkness.net/dq/games/nes/dw3/maps/world
      For download, videos, and example of created world file data; please visit the MapIt webpage: http://songersoft.com/programming/mapit/mapit_about.phtml
    • Atoxis
      By Atoxis
      Howdy, I've gone through a lot of au3 forums, and I once had a working Imagesearch script that I got from here.  However, and i'm just totally not sure how but my imagesearch scripts aren't working anymore.
      I'm not new to au3 but i'm not the most experienced with it's syntax/commands.

      Anyways, I've looked over the big threads involving imagesearch.

      Does anyone have a working Imagesearch x64 for win10 that is currently working as of the date with the post.

      Dll's and what not is fine, just when I tell the script to run, I want to be able to find the image on the screen!
      Can't find a working copy so if anyone has one please send it my way lol.

      I've taken all the imagesearch downloads and what not and have played with them but I can't get any of them working on my end, despite others saying they're working.
      Thanks.
    • 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
    • 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)
×