Jump to content
Sign in to follow this  
johnmcloud

[SOLVED] Load image from URL

Recommended Posts

johnmcloud

Hi guys, i have a little problem with a $var of this script, i don't know how to make it:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <String.au3>
#include <File.au3>

Global $image

$GUI = GUICreate("Test GUI", 466, 360, -1, -1)
$InfoButton = GUICtrlCreateButton("Info", 14, 312, 123, 25)
$WebPic = GUICtrlCreatePic(_GetURLImage('"' & $image & '"'), 16, 216, 120, 90)
If @error = 1 Then
$GroupPic = GUICtrlCreateGroup("", 15, 210, 120, 100)
EndIf
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $InfoButton
   Read_Info()
EndSwitch
WEnd

Func Read_Info()
Dim $logfile = @WorkingDir & "\test.txt"
If FileGetSize($logfile) <> 0 Then
  Global $image = FileReadLine($logfile, 2)
  MsgBox(0,0, FileReadLine($logfile, 2))
EndIf
EndFunc   ;==>Read_Info

Func _GetURLImage($sURL, $sDirectory = @TempDir)
Local $hDownload, $sFile
$sFile = StringRegExpReplace($sURL, "^.*/", "")
If @error Then
  Return SetError(1, 0, $sFile)
EndIf
If StringRight($sDirectory, 1) <> "\" Then
  $sDirectory = $sDirectory & "\"
EndIf
$sDirectory = $sDirectory & $sFile
If FileExists($sDirectory) Then
  Return $sDirectory
EndIf
$hDownload = InetGet($sURL, $sDirectory, 17, 1)
While InetGetInfo($hDownload, 2) = 0
  If InetGetInfo($hDownload, 4) <> 0 Then
   InetClose($hDownload)
   Return SetError(1, 0, $sDirectory)
  EndIf
  Sleep(105)
WEnd
InetClose($hDownload)
Return $sDirectory
EndFunc   ;==>_GetURLImage

The Test.txt

blabla
dizziness-and-balance.com/images/eye-chart.jpg
blabla

I have removed the http://www. on the forum, but on the file the link is full

On MsgBox or ConsoleWrite i see the full link ( the link posted change everytime, so i can't make a direct link to the image on PC ) but the image is not loaded on GUI.

What is the problem?

Thanks for support :)

Edited by johnmcloud

Share this post


Link to post
Share on other sites
AlmarM

I think it's because you are trying to load an image from the web.

Try download it first using the INet functions and save it somewhere local.


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites
johnmcloud

Thanks AlmarM, but i don't think is the problem, because _GetUrlImage() download the image on PC and give me the directory position, in @Tempdir &amp; "nameofthefile.jpeg"

Edited by johnmcloud

Share this post


Link to post
Share on other sites
AlmarM

Thanks AlmarM, but i don't think is the problem, because _GetUrlImage() download the image on PC and give me the directory position, in @Tempdir &amp; "\nameofthefile.jpeg"

Ah, I oversaw that.

Whats the reason you are adding a " twice in the _GetURLImage?

$WebPic = GUICtrlCreatePic(_GetURLImage('"' & $image & '"'), 16, 216, 120, 90)

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites
johnmcloud

Because i can't make it without :)

GetImageUrl("http://qwerty") - work

GetImageUrl(http://qwerty) - not work

My problem is set the $var, with link work, with the variable not, but the consolewrite give me the right url. Try it.

Share this post


Link to post
Share on other sites
AlmarM

Because i can't make it without Posted Image

GetImageUrl("http://qwerty") - work

GetImageUrl(http://qwerty) - not work

My problem is set the $var, with link work, with the variable not, but the consolewrite give me the right url. Try it.

First of all, remove those 2 ". It's no use since you are using a variable.

Second, the link inside the text.txt is correct, but the link provided by the _GetURLImage returns only @TempDir.

Therefore the image will not show because the _GetURLImage doesn't return the filename + extension.

MsgBox(0, "", _GetURLImage($image))

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites
UEZ

Try this:

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
johnmcloud

Guys, maybe i'm not so clear, my problem is not with the script, the script work file, take a look:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <String.au3>
#include <File.au3>

$GUI = GUICreate("Test GUI", 466, 360, -1, -1)
$InfoButton = GUICtrlCreateButton("Info", 14, 312, 123, 25)
$WebPic = GUICtrlCreatePic(_GetURLImage("http://www.autoitscript.com/forum/uploads/profile/photo-thumb-29844.jpg"), 16, 216, 120, 90)
If @error = 1 Then
$GroupPic = GUICtrlCreateGroup("", 15, 210, 120, 100)
EndIf
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd

Func _GetURLImage($sURL, $sDirectory = @TempDir)
Local $hDownload, $sFile
$sFile = StringRegExpReplace($sURL, "^.*/", "")
If @error Then
  Return SetError(1, 0, $sFile)
EndIf
If StringRight($sDirectory, 1) <> "" Then
  $sDirectory = $sDirectory & ""
EndIf
$sDirectory = $sDirectory & $sFile
If FileExists($sDirectory) Then
  Return $sDirectory
EndIf
$hDownload = InetGet($sURL, $sDirectory, 17, 1)
While InetGetInfo($hDownload, 2) = 0
  If InetGetInfo($hDownload, 4) <> 0 Then
   InetClose($hDownload)
   Return SetError(1, 0, $sDirectory)
  EndIf
  Sleep(105)
WEnd
InetClose($hDownload)
Return $sDirectory
EndFunc   ;==>_GetURLImage

Oh, @AlmarM, The func _GetURLImage give me the full directory + extension:

ConsoleWrite(_GetURLImage("http://www.autoitscript.com/forum/uploads/profile/photo-thumb-29844.jpg")

Result is:

C:DOCUME~1WINDOW~1IMPOST~1Tempphoto-thumb-29844.jpg

For the "" you have right, it's useless but the result is the same. I'll remove them

Resume, i want to do this:

1) Open the script, no image ( i have did it with if @error = 1 )

2) Click on info button --> _GetURLImage --> load image into GUI

So my problem is i don't know how to do the 2), i need help for this. Thanks to all

Edited by johnmcloud

Share this post


Link to post
Share on other sites
johnmcloud

Maybe i have resolved by myself with this:

$var = _GetURLImage("http://www.autoitscript.com/forum/uploads/profile/photo-thumb-29844.jpg")
GUICtrlSetImage($WebPic, $var)

I'll test it and post the result later

EDIT: Yes, work

Thanks anyway to UEZ and AlmarM :)

Edited by johnmcloud

Share this post


Link to post
Share on other sites
passimage

here are some codes on how to load image from url vb.net.

Imports System.IO
Imports System.Drawing.Printing
Imports RasterEdge.Imaging
Imports RasterEdge.Imaging.Processing

Dim Image As New RasterEdgeImaging()

Image.GetImageFromURL("http://www.rasteredge.com/1.jpg")
If _Image IsNot Nothing Then
pictureBox1.Image = _Image
Image.Save("C:1.jpg")
End If

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
Sign in to follow this  

  • Similar Content

    • Rocker
      By Rocker
      I apologize for my poor coding skills, but only on occasion do I have a need to automate a repetitious task to save time.  In a nutshell the following code is supposed to go to a website, save the site using Scrapbook (a plugin used by an older version of Firefox), rename the folder in Windows Explorer that Scrapbook assigns a random name for and then moves on to the next website, of which there are hundreds.  Everything works, except after the address bar gets populated with the URL, it's like the ENTER key never gets pushed.  The weird thing is, this worked yesterday before I left to go home and when I came in this morning it didn't work.  The next thing I'll be trying to learn is to loop this with a the list of the websites.  Thank you for your help!
      WinActivate( "[CLASS:MozillaWindowClass]" ) ;Apply focus to the open Mozilla firefox window Sleep(500) Send("^k") ;Apply focus to the address bar Sleep(500) Send("www.WEBSITE.com {ENTER}") ;Send the website to the address bar Sleep(10000) ;Wait for the website to fully open Send("!c") ;Opens the drop down menu for Scrapbook Sleep(2000) Send("{ENTER}") ;Selects the default drop down selection of save Sleep(20000) WinActivate( "[CLASS:CabinetWClass]" ) ;Applies focus to the open Windows Explorer window where the websites are saved Sleep(1000) Send("{SPACE}") ; Selects a folder in the folders list Sleep(200) Send("{HOME}") ;Moves to the top folder Sleep(200) Send("{F2}") ;Keyboard shortcut to rename the folder Sleep(200) Send("www.WEBSITE.com {ENTER}") ;Applies the new name to the folder  
    • 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.
    • 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.  
    • 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)
    • nacerbaaziz
      By nacerbaaziz
      Hello all
      I have a question please
      I have a link to an .exe file
      for example this link
      https://www.nvaccess.org/files/nvda/releases/2017.1/NVDA_2017.1.exe
      I want to check if the link is exists orno
      surely  Without downloading the file
      is there any  function or a way to  do this?
      Thanks in advance
×