show the image of web to the gui Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
xuezhe
Posts: 87
Joined: 06 Jan 2016, 11:02

show the image of web to the gui

17 Dec 2017, 06:18

Could you help me . thx.
I don't want to download it to the disk.
teadrinker
Posts: 387
Joined: 29 Mar 2015, 09:41
Contact:

Re: show the image of web to the gui

17 Dec 2017, 09:23

This works on Windows 7:

Code: Select all

url := "https://upload.wikimedia.org/wikipedia/commons/5/55/Tesseract.gif"
width := 200
height := 200
Gui, New, -DPIScale
Gui, Add, ActiveX, w%width% h%height% voDoc, htmlfile
oDoc.Write("<body style='margin: 0; overflow: hidden;'><img src='" url "' width='" width "' height='" height "'></body>")
Gui, Show
return

GuiClose:
   ExitApp
I'm not sure, whether it will work if you use Windows XP.
xuezhe
Posts: 87
Joined: 06 Jan 2016, 11:02

Re: show the image of web to the gui

17 Dec 2017, 10:08

teadrinker wrote:This works on Windows 7:

Code: Select all

url := "https://upload.wikimedia.org/wikipedia/commons/5/55/Tesseract.gif"
width := 200
height := 200
Gui, New, -DPIScale
Gui, Add, ActiveX, w%width% h%height% voDoc, htmlfile
oDoc.Write("<body style='margin: 0; overflow: hidden;'><img src='" url "' width='" width "' height='" height "'></body>")
Gui, Show
return

GuiClose:
   ExitApp
I'm not sure, whether it will work if you use Windows XP.
I know it.thx all the same.
But I want to get the data of imge to show in the gui(no downloading the image to disk).
teadrinker
Posts: 387
Joined: 29 Mar 2015, 09:41
Contact:

Re: show the image of web to the gui  Topic is solved

17 Dec 2017, 22:48

Code: Select all

imageUrl := "http://icons.iconarchive.com/icons/aha-soft/jewelry/256/Gem-icon.png"
Gui, Add, Pic,, % "HBITMAP:" . GetHBitmapFromImageURL(imageUrl)
Gui, Show
return

GuiClose:
   ExitApp
   
GetHBitmapFromImageURL(url)  {
   oWhr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
   oWhr.Open("GET", url, false)
   oWhr.Send()
   if (oWhr.Status != 200)  {
      MsgBox, Failed to load the image!
      Return
   }
   contentType := oWhr.GetResponseHeader("Content-Type")
   if !InStr(contentType, "image")  {
      MsgBox, URL doesn't link to an image!
      Return
   }
   Return (new GDIp).HBitmapFromIStream(oWhr.ResponseStream)
}

class GDIp   {
   __New() {
      if !DllCall("GetModuleHandle", Str, "gdiplus", Ptr)
         DllCall("LoadLibrary", Str, "gdiplus")
      VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
      DllCall("gdiplus\GdiplusStartup", UPtrP, pToken, Ptr, &si, Ptr, 0)
      this.token := pToken
   }
   
   __Delete()  {
      DllCall("gdiplus\GdiplusShutdown", Ptr, this.token)
      if hModule := DllCall("GetModuleHandle", Str, "gdiplus", Ptr)
         DllCall("FreeLibrary", Ptr, hModule)
   }
   
   HBitmapFromIStream(IStream)  {
      pStream := ComObjQuery(IStream, "{0000000C-0000-0000-C000-000000000046}")
      DllCall("gdiplus\GdipCreateBitmapFromStream", Ptr, pStream, PtrP, pBitmap)
      ObjRelease(pStream)
      DllCall("OleAut32\VariantClear", PtrP, IStream)
      DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", Ptr, pBitmap, PtrP, hBitmap, UInt, 0xFFFFFFFF)
      DllCall("gdiplus\GdipDisposeImage", Ptr, pBitmap)
      Return hBitmap
   }
}
Something like this?
xuezhe
Posts: 87
Joined: 06 Jan 2016, 11:02

Re: show the image of web to the gui

18 Dec 2017, 06:02

teadrinker wrote:

Code: Select all

imageUrl := "http://icons.iconarchive.com/icons/aha-soft/jewelry/256/Gem-icon.png"
Gui, Add, Pic,, % "HBITMAP:" . GetHBitmapFromImageURL(imageUrl)
Gui, Show
return

GuiClose:
   ExitApp
   
GetHBitmapFromImageURL(url)  {
   oWhr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
   oWhr.Open("GET", url, false)
   oWhr.Send()
   if (oWhr.Status != 200)  {
      MsgBox, Failed to load the image!
      Return
   }
   contentType := oWhr.GetResponseHeader("Content-Type")
   if !InStr(contentType, "image")  {
      MsgBox, URL doesn't link to an image!
      Return
   }
   Return (new GDIp).HBitmapFromIStream(oWhr.ResponseStream)
}

class GDIp   {
   __New() {
      if !DllCall("GetModuleHandle", Str, "gdiplus", Ptr)
         DllCall("LoadLibrary", Str, "gdiplus")
      VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
      DllCall("gdiplus\GdiplusStartup", UPtrP, pToken, Ptr, &si, Ptr, 0)
      this.token := pToken
   }
   
   __Delete()  {
      DllCall("gdiplus\GdiplusShutdown", Ptr, this.token)
      if hModule := DllCall("GetModuleHandle", Str, "gdiplus", Ptr)
         DllCall("FreeLibrary", Ptr, hModule)
   }
   
   HBitmapFromIStream(IStream)  {
      pStream := ComObjQuery(IStream, "{0000000C-0000-0000-C000-000000000046}")
      DllCall("gdiplus\GdipCreateBitmapFromStream", Ptr, pStream, PtrP, pBitmap)
      ObjRelease(pStream)
      DllCall("OleAut32\VariantClear", PtrP, IStream)
      DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", Ptr, pBitmap, PtrP, hBitmap, UInt, 0xFFFFFFFF)
      DllCall("gdiplus\GdipDisposeImage", Ptr, pBitmap)
      Return hBitmap
   }
}
Something like this?
:clap:
yeah.perfect. thx.
xuezhe
Posts: 87
Joined: 06 Jan 2016, 11:02

Re: show the image of web to the gui

18 Dec 2017, 06:05

I have a another problem for ocring the code of dom.Could you have a try to help me ?
https://autohotkey.com/boards/viewtopic.php?f=5&t=41419
teadrinker
Posts: 387
Joined: 29 Mar 2015, 09:41
Contact:

Re: show the image of web to the gui

18 Dec 2017, 06:18

Sorry, no idea. I can't read Chinese. :)

Return to “Ask For Help”

Who is online

Users browsing this forum: mshall, roysubs, swagfag and 28 guests