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 & HelpPrograms › How to convert PImage to GIF/JPG
Page Index Toggle Pages: 1
How to convert PImage to GIF/JPG? (Read 1453 times)
How to convert PImage to GIF/JPG?
May 23rd, 2005, 2:37pm
 
I need an image as a byte-array, how would i go about doing that? I'm going to use it to send the image as an attachment.. the only thing i need is to convert the image to binary

Any pointers would be greatly appreciated

-seltar
Re: How to convert PImage to GIF/JPG?
Reply #1 - May 23rd, 2005, 6:57pm
 
i've come a bit furter, but the problem is that the PImage isn't any fileformat from start, just a PImage, so when i convert that info to binary, i don't get an image, just a file with the binaryinformation to PImage..

anybody have any idea on this.. i would really like to be able to take a screenshot of the applet, and send it via mail..
the mail part is working fine, but i need to make the PImage into gif, or jpg without having to save it first.

is there a way to do that?

-seltar
Re: How to convert PImage to GIF/JPG?
Reply #2 - May 23rd, 2005, 11:44pm
 
there's some info about this on the old alpha board:
http://processing.org/discourse/yabb/YaBB.cgi?board=;action=search

i think if you use "processing.org" instead of as.processing.org you'll have better luck getting to it (you can avoid the "enter search string" error). it's working for me. if not, you may need to reboot your machine so that it updates to the new web address for processing.org.
Re: How to convert PImage to GIF/JPG?
Reply #3 - May 24th, 2005, 5:04pm
 
The Alpha board still didn't work yesterday, so i copied the htmlcode, made a new file, and changed the <form action="http://processing.blabla to as.processing.blabla, and that works fine now..
so i can search with my little html file , but i couldn't find anything about converting a PImage to a gif or jpg String.. unfortunately..
so if anybody has any ideas, i'd be really happy Smiley

-seltar
Re: How to convert PImage to GIF/JPG?
Reply #4 - May 25th, 2005, 3:30am
 
these two are some of the ones i was referring to:

http://processing.org/discourse/yabb/YaBB.cgi?board=Tools;action=display;num=1066742994

http://processing.org/discourse/yabb/YaBB.cgi?board=Integrate;action=display;num=1106908696
Re: How to convert PImage to GIF/JPG?
Reply #5 - May 25th, 2005, 10:02am
 
this is what i ended up with:

Code:

import com.sun.image.codec.jpeg.*;

ByteArrayOutputStream bufferImage(){
ByteArrayOutputStream out = new ByteArrayOutputStream();
BufferedImage img = new BufferedImage(width, height, 2);
img = (BufferedImage)createImage(width, height);
loadPixels();
for(int i = 0; i < width; i++)
{
for(int j = 0; j < height; j++)
{
int id = j*width+i;
img.setRGB(i,j, pixels[id]);
}
}
try{
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(img);
}
catch(FileNotFoundException e){
System.out.println(e);
}
catch(IOException ioe){
System.out.println(ioe);
}
return out;
}

ByteArrayOutputstream b = bufferImage();
byte bytes[] = b.toByteArray();


ByteArrayOutputstream is reading to memory, instead of file (which applets aren't allowed to), so this way, i was able to save a jpg of the current screen to memory, which i then encoded with base64, and added as an attachment to an email..

-seltar
Page Index Toggle Pages: 1