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
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

    • 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
    • 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!
    • fatpig
      By fatpig
      Dear AutoIT Community.
      I am currently working on a program that will display lots of images in a scroll down GUI.
      I create the GUI based on the number of images, which works fine.
      But all images I place using GuiCtrlCreatePic above a threshold of around 32000 pixels (cant say exactly) are placed at negative locations and finally will reach 0 again
      and will then populate on top of the images placed there before.
      For $i = 1 To $Images[0] ; Get picture dimensions $hImage = _GDIPlus_ImageLoadFromFile($ImgRep & $Images[$i]) $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) ; Resize & place images in GUI $Pic[$i] = GUICtrlCreatePic($ImgRep & $Images[$i], $Spacer, Round($yPos, 0), $MaxImgWidth, $MaxImgWidth * ($iY / $iX)) $yPos = $yPos + $MaxImgWidth * ($iY / $iX) + $Spacer $log = $log & "|" & $yPos $currentlut = $Images[1] Next I have found a limit at 32767 pixels for some GUI elements when googling around.
      Can someone tell me how to circumvent that?
      thanks!
      cheers
      Felix
×