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 › loadImage an extension-less image
Page Index Toggle Pages: 1
loadImage an extension-less image (Read 1453 times)
loadImage an extension-less image
Dec 3rd, 2006, 2:36pm
 
Hi everyone!

I try to download an image which is :
http://re3.mm-a5.yimg.com/image/1987833668

with:
PImage img = loadImage("http://re3.mm-a5.yimg.com/image/1987833668");
image(img, 0, 0);

i catch this exception:
java.lang.NullPointerException
at processing.core.PGraphics.image(PGraphics.java:1999)
at processing.core.PApplet.image(PApplet.java:7149)
at Temporary_2080_5201.draw(Temporary_2080_5201.java:77)
at processing.core.PApplet.handleDisplay(PApplet.java:1318)
at processing.core.PGraphics.requestDisplay(PGraphics.java:564)
at processing.core.PApplet.run(PApplet.java:1413)
at java.lang.Thread.run(Unknown Source)

I hope for you that this link will be still alive when you will read my problem ;).

This code was working for pictures with filetype like "*
.jpg" just before i've tried to load a picture without extension.

I'm not sure but it seems that loadImage watch by himself the filetype of the picture. So is it possible to tell processing what filetype it is?

I hope someone can help me or tell me a solution!
Thank you in advance!!

Fred
Re: loadImage an extension-less image
Reply #1 - Dec 3rd, 2006, 8:42pm
 
unfortunately it needs the extension.. some ways to work around it:

1) you can actually add .jpg to the url in this case, because yahoo just ignores it:
http://re3.mm-a5.yimg.com/image/1987833668.jpg

2) if that weren't the case, you could probably cheat by using:
http://re3.mm-a5.yimg.com/image/1987833668?.jpg
because the ? wouldn't be interpreted by the server as part of the url. that wouldn't work if there's already a ? in the name, but it would cover some cases.

3) you could use loadBytes(), followed by java's Toolkit.getImage(), and do "new PImage()" on that:
Code:

byte[] b = loadBytes("someurl");
Image javaImage = Toolkit.createImage(b);
PImage image = new PImage(javaImage);

(not tested, but something like that should work)
Re: loadImage an extension-less image
Reply #2 - Jan 30th, 2007, 1:02am
 
for rev 0124, loadImage() has been altered such that:

+ if no extension is specified, it will attempt to load the image as png/jpg/gif.

+ a second version of loadImage() has been added with a parameter that lets you specify the proper extension for the image, i.e. loadImage("somelongurl", "jpg")

http://dev.processing.org/bugs/show_bug.cgi?id=500
Re: loadImage an extension-less image
Reply #3 - Apr 19th, 2007, 11:15am
 
Hello!, I came here, with the same problem as the OP. Adding the second parameter works Smiley thank you!

Still, with no indication of type in the url, loadimage outputs this: "Could not find a method to load http://... " Can't processing take the server supplied mime-type from the http-header, in this case "Content-Type: image/jpeg" to find out, if it can handle the file?

Just my two cents, in my setup I can make it so, only jpegs are ever sent, yet in a perfect world...

Peter
Re: loadImage an extension-less image
Reply #4 - Apr 20th, 2007, 2:34pm
 
the perfect world doesn't really exist and we can't rely on the mime configuration on the server to be correct.

the "could not find a method" is an error if it's actually working, please file as a bug.
Page Index Toggle Pages: 1