View Full Version : Saving images

02 February 2004, 09:39 PM
:wavey: Hi I'm new to the forum, and I was wondering if anyone could help me concerning saving images? I have written a funky little ray tracer, and I want to expand it into an animation generator, but I need to be able to save renderings. My images are stored as a width x height integer array, and I need to be able to dump it in a suitable format.

Did I mention that the ray tracer was written in good old dependable fast Java? It is. My main problem really is knowing how the formatting for, say, the Raw format is. If I try to save my "raw" images and open them in adobe, they come out weird...

Just the sample outputter :

public void dumpTo(File f) throws IOException {
byte image[] = new byte[pixels.length*3];
for (int counter = 0; counter < pixels.length; counter ++) {

image[3*counter] = (byte)((pixels[counter])&255);
image[3*counter+1] = (byte)((pixels[counter]>>8)&255);
image[3*counter+2] = (byte)((pixels[counter]>>16)&255);

CAMByteFileHandler.writeBinaryFile(f, image);

Where pixels[] is the integer array, and the CAMByteFileHandler simply dumps the byte array to the disk.

Any suggestions? Its coming out really weird!!! And I don't know any fancy image storage algorithms such as gif/jpg, or even how to write the header info etc in Java for a bmp...

02 February 2004, 11:38 PM
maybe this helps

02 February 2004, 09:20 AM
Also, your pixel data should really be floating point. Then you can always convert to 8-bit, 16-bit short or half float or whatever when you output to file

02 February 2004, 02:15 PM
Alrighty!! Very nice. I will use some of these. I especially like the animated gif autogeneration... might have to try that =)

Gonna start making some nice little demo movies in graphics =)

CGTalk Moderation
01 January 2006, 10:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.