Loading images from the web?
BlitzMax Forums/BlitzMax Beginners Area/Loading images from the web?
| ||
Hey all. Using the stream command to load data from a webpage, Blitz Example:in = ReadStream("http::blitzbasic.com") If Not in RuntimeError "Failed to open stream" While Not Eof(in) Print ReadLine(in) Wend CloseStream in That displays all the HTML code, which is neat, but is there any way to load an image that you know will always be there: Example: (didnt want the real link, its a big picture!) (add the http)://goes.gsfc.nasa.gov/goeswest/pacific/color/0000_latest.jpg That will theoretically always be there, waiting for you to grab it. I thought it would be kind of cool to grab snapshots of satellite images every few hours, make an animation, save for posterity, etc. Any pointers would be appreciated! |
| ||
I was possessed by the spirit of Skidracer...According to the Wiki, at least... ;o)Graphics 400, 300, 0 DrawText "Getting Image...", 140, 144 Flip img:TImage = LoadImage(LoadBank("http::goes.gsfc.nasa.gov/goeseast/hurricane2/color_lrg/latest.jpg")) If Not img Then RuntimeError "Unable to download image" Graphics img.width, img.height, 0 DrawImage img, 0, 0 Flip WaitKey() End |
| ||
Nice ! |
| ||
Thanks to both of you!!! Thats EXACTLY what I was lookin for!!! PERFECT!!! Now just where the heck did Skid share this??!?! I was searching the forums. Maybe I didn't word it right? Just for future reference of course!!! |
| ||
Um....now anyone have a way of SAVING jpgs from a TImage? I saw xacto had a little beta of some work he was doing: http://www.blitzmax.com/Community/posts.php?topic=41965 cept now its outdated and doesn't work, somn about a fontglyph error. Course that was made back in December. Anyone? :) I wont push my luck, I can still save out as PNG, but they're pretty giant compared to JPGs. :) I already searched the forums with no luck. |
| ||
. |
| ||
I'll probably find a use for this at some point, so I had a quick fiddle with Jeffrey's code, and a re-write of 'JPGLoader.bmx' later... Overwrite 'mod/brl.mod/JPGLoader.mod/JPGLoader.bmx' with... Overwrite 'mod/pub.mod/libjpeg.mod/libjpeg.bmx' with... Overwrite 'mod/pub.mod/libjpeg.mod/libjpeg.c' with... From the IDE, do a 'Program>Build Modules', and you should be good to go after a restart. You may also want to... <BMAX PATH>/bin/bmk docmods <BMAX PATH>/bin/bmk syncdocs...as I don't think 'Build Mods' does this. |
| ||
Thanks! Thats totally cool! |
| ||
Any chance the SaveJPG can be included in the official build? |
| ||
hang on, how do you save a file you stream in, with identical data? for example if he's streaming in a jpeg, surely it is already a jpeg? |
| ||
Yup!...You could just save the bank...jpgBnk:TBank = LoadBank("http::goes.gsfc.nasa.gov/goeswest/pacific/color/0000_latest.jpg") If Not jpgBnk Then RuntimeError "Unable to download image" 'img:TImage = LoadImage(jpgBnk) '...ETC... SaveBank(jpgBnk, "c:/test image.jpg") End But as I said, I'd probably be needing the ability to save JPGs anyway and Jeffrey had already done 99.9% of the work. Also, Booticus might want to manipulate the image in some way before saving. |
| ||
Hell yeah to both of ya!!! These are perfect bits of code for me and anyone else interested in!!! Now One eyed jack, are you releated to Two eyed Pete?? The names and all. ;) |
| ||
Can someone please make Jeremy's code to work with bmx 1.18. I only need a "SavePixmapJPG" function. |
| ||
SavePixmapJPeg will feature in the next update. |
| ||
I guess I can wait that long! :) Thanks for letting us know of this!!!!!!!!!!!!! |
| ||
when i execute your code : in=ReadStream("http::blitzbasic.com") If Not in RuntimeError "Failed to open a ReadStream to file" While Not Eof(in) Print ReadLine(in) Wend CloseStream in I receive the following error. what is bad ? BlitzMax Debug Report: Unhandled Exception:Failed to open a ReadStream to file End of Debug Report. |
| ||
The program is trying to connect to the internet. If you have a firewall then you need to allow access for this program. If you have a firewall and don't get a 'allow/deny' pop-up then you're being prevented by your firewall policy. |
| ||
I'm using a proxy. How to set the source to bypass proxy ? |
| ||
@Yan: thats some juicy bit code you have given us there,big thank you from me |