maniootek Posted March 24, 2021 Share Posted March 24, 2021 This is first time I need to load picture to my GUI from URL and I did some research about it. I found only this solution: I have converted this to funtion: #include-once #cs original script: https://www.autoitscript.com/forum/topic/164419-updating-guictrlcreatepic-with-image-url/?do=findComment&comment=1199349 coded by UEZ 2011 #ce #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <WinAPI.au3> Func _GUICtrlSetPicFromUrl($idGUICtrlPic, $Url) ;check the control pos and size Local $aPos = ControlGetPos(_WinAPI_GetParent(GUICtrlGetHandle($idGUICtrlPic)), "", $idGUICtrlPic) _GDIPlus_Startup() Local Const $STM_SETIMAGE = 0x0172 Local Const $hBmp = _GDIPlus_BitmapCreateFromMemory(InetRead($Url), True) Local Const $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp) Local Const $iWidth = _GDIPlus_ImageGetWidth($hBitmap) Local Const $iHeight = _GDIPlus_ImageGetHeight($hBitmap) GUICtrlSendMsg($idGUICtrlPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp) _WinAPI_DeleteObject($hBmp) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() ;resize control back to it's original size if size of the image is bigger than control size if $iWidth > $aPos[2] or $iHeight > $aPos[3] then GUICtrlSetPos($idGUICtrlPic, $aPos[0]-1, $aPos[1]-1, $aPos[2], $aPos[3]) ;here I had to use "-1" to change position because otherwise it does not work EndIf EndFunc I was wondering if there is any other way to do this? My research is from 2014 Link to comment Share on other sites More sharing options...
UEZ Posted March 24, 2021 Share Posted March 24, 2021 (edited) 6 hours ago, maniootek said: I was wondering if there is any other way to do this? Why? Is it not working? What kind other way are you looking for? Of course, you can save the image first to disk and load it afterwards to your script. Edited March 24, 2021 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 More sharing options...
maniootek Posted April 2, 2021 Author Share Posted April 2, 2021 It is working but I thought maybe there is simpler way to do this. I am wondering why I need to move picture control to make the picture appear? Or how can I change the size of the image to fit the control instead of fitting big image to the smaller control (quality of picture is not good) Link to comment Share on other sites More sharing options...
Nine Posted April 2, 2021 Share Posted April 2, 2021 Maybe by using resize : #include <GUIConstants.au3> #include <GDIPlus.au3> #include <WinAPI.au3> Const $URL = "https://www.autoitscript.com/forum/uploads/monthly_2021_04/image.png.552f1c90192fed33bad1e8748f470c71.png" _GDIPlus_Startup() Local $hGUI = GUICreate("Example Resize") Local $hImage = _GDIPlus_BitmapCreateFromMemory(InetRead($URL)) Local $iWidth = Int(_GDIPlus_ImageGetWidth($hImage) * 0.75) ; New size Local $iHeight = Int(_GDIPlus_ImageGetHeight($hImage) * 0.75) Local $hImageResized = _GDIPlus_ImageResize($hImage, $iWidth, $iHeight) _GDIPlus_ImageDispose($hImage) Local $idPic = GUICtrlCreatePic("", 10, 10, $iWidth, $iHeight) Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageResized) _GDIPlus_ImageDispose($hImageResized) GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap) GUISetState() While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _WinAPI_DeleteObject($hBitmap) _GDIPlus_Shutdown() maniootek 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
maniootek Posted April 2, 2021 Author Share Posted April 2, 2021 Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now