We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › using openstream for internet files
Page Index Toggle Pages: 1
using openstream for internet files (Read 1021 times)
using openstream for internet files
Oct 14th, 2005, 5:20pm
 
hi

using this to retrieve an image online and display it...

size(600, 600);
PImage pasted_image = loadImage("http://www.ezthemes.com/previews/d/dog.jpg");
image(pasted_image, 10, 0);

(be careful of the link above it seems to have included the last quote as part of the url)

this works fine with local images but not with a url?  just based on previous experience with other apps and loading images from the internet shouldn't this have to wait until the image loads before it displays it - is this the issue or am i missing something else here?  thanks in advance.

a+
gar
Re: using openstream for internet files
Reply #1 - Oct 14th, 2005, 5:30pm
 
sorry just starting to learn processing and I confused LOadimage with openstream.  what I should have said was...

size(600, 600);
PImage pasted_image = openStream("http://www.ezthemes.com/previews/d/dog.jpg");
image(pasted_image, 10, 0);

this is also producing an error...

C:/DOCUME~1/gl19/LOCALS~1/Temp/build/Temporary_4188_1938.java:2:8:2:78: Semantic Error: The type of the right sub-expression, "java.io.InputStream", is not assignable to the variable, of type "processing.core.PImage".

any help appreciated.

a+
gar
Re: using openstream for internet files
Reply #2 - Oct 14th, 2005, 6:24pm
 
Works fine for me:

size(520,60);
PImage im = loadImage("http://processing.org/images/processing_beta.gif");
image(im,10,10);
Re: using openstream for internet files
Reply #3 - Oct 14th, 2005, 7:12pm
 
few things:

1) for much improved ease of use loadImage() does indeed block further execution until the image is fully downloaded (or an error occurred)

2) loading images via URL will only work locally (from within the PDE) or online only if the image URL is in the same domain as the applet.

3) you can load images in the backgroud whilst continuing with your applet by using Java's MediaTracker class, but then you'll also be on your own converting the downloaded image (in standard JavaAWT format) into a Processing PImage object. Have a look at the PApplet source to see how it's done...
Re: using openstream for internet files
Reply #4 - Oct 17th, 2005, 10:52pm
 
beachmeat wrote on Oct 14th, 2005, 6:24pm:
Works fine for me:

size(520,60);
PImage im = loadImage("http://processing.org/images/processing_beta.gif");
image(im,10,10);


just tried your code and it works perfectly.  on a different computer now and the other was behind a firewall I'm guessing it was that.

toxi wrote on Oct 14th, 2005, 6:24pm:
2) loading images via URL will only work locally (from within the PDE) or online only if the image URL is in the same domain as the applet.


mmm i can understand the applet doing that, shockwave used to do the same thing for security reasons.  well that will need a rethink then.  is loadimage the correct one to use here or should i be using openstream

thanks for your help - both of you.

a+
gar
Page Index Toggle Pages: 1