Loading image from website

BlitzMax Forums/BlitzMax Programming/Loading image from website

Gavin Beard(Posted 2006) [#1]
Hi, i want to be able to load an image from a website or ftp direct into a tImage or pixmap? is this possible?


Perturbatio(Posted 2006) [#2]
you should just be able to specify http:: as the protocal in the image url (AFAIK).


Gavin Beard(Posted 2006) [#3]
:| so local x:tImage = loadimage ("http://xxx.jpg")


xlsior(Posted 2006) [#4]
Here's a snippet that Skidracer posted a while back:

Graphics 400, 300, 0

DrawText "Getting Image...", 140, 144
Flip 

img:TImage = LoadImage(LoadBank("http::www.domain.com/images/image.jpg"))
If Not img Then RuntimeError "Unable to download image"

'Graphics img.width, img.height, 0 
Graphics 1024,768

DrawImage img, 0, 0
Flip

WaitKey()

End



xlsior(Posted 2006) [#5]
:| so local x:tImage = loadimage ("http://xxx.jpg")


No -- you don't use http:// as a prefix, but http:: when using streams. Just like you would use IncBin::filename.jpg when addressing an image file that has been included into your .exe with with the incbin command.

But trying to load the image directly over HTTP without storing it in a bank first doesn't seem to work.


Yan(Posted 2006) [#6]
Because the pixmap loaders expect a seekable stream, you need to load the image into a bank first...

Strict

Graphics 640, 480, 0

Local image:Timage = LoadImage(LoadBank("http::blitzbasic.com/img/brllogo-thin.png"))

Cls
DrawImage image, 100, 100

Flip

WaitKey()


[edit]
Bah...You fellas are too fast for me. ;o)

@xlsior - I think you'll find that's my code. ;o)
http://www.blitzbasic.com/Community/posts.php?topic=50729#565158
[/edit]


Filax(Posted 2006) [#7]
I dont knew this stuff ! :) cool :)


Gavin Beard(Posted 2006) [#8]
hey thanks everyone, u r all so great ;)


TartanTangerine (was Indiepath)(Posted 2006) [#9]
I never knew that, thanks all.


Ziltch(Posted 2006) [#10]
Thanks for that tip!

To get a web image and save it to a file, I have been using this code;

Function GetHTTPpic(PicAddr:String,NewPicFile:String)
	If NewPicFile Then
		Local wwwAddr = ReadStream(PicAddr)
		Local stream = WriteStream(NewPicFile)
		CopyStream(wwwAddr,stream)
		CloseStream wwwAddr 
		CloseStream stream
	EndIf
End Function



xlsior(Posted 2006) [#11]
@xlsior - I think you'll find that's my code. ;o)


Oops, sorry... I had the snippet saved to my HD, but had somehow attributed it to Skidracer. Sorry about that. :-?