saveFrame() > P3D > black and white pics!?‏

Hi, I’m trying to use saveFrame() with a P3D canvas and that results in black and white shapes instead of the colors I see!? Any ideas why and how to fix this? Thanks!

Answers

  • I'm not seeing this. Do you have a code example that shows this behavior?

  • I've actually noticed by now that the problem only arises when I try to save the images as GIFs! It works with jpg, png, tif and tga ... Is that a know limitation of saving as GIF in P3D?

  • GIF is not a supported output format.

    See the reference: http://www.processing.org/reference/saveFrame_.html

  • Wow, that's surprising! So why does it usually work then afterall?

    Also, some stuff in P3D gets saved correctly in GIF too. Weird ... I haven't identified yet why this specific code results in b&w GIFs!?

  • edited February 2014 Answer ✓

    Not sure. There could be different explanations...

    Looking for answers I turned to the source code. My findings:

    • saveFrame in PApplet calls save() on the main PGraphics g
    • Since PGraphics extends PImage, that's where the actual save() method is.
    • The save() method goes over the list of write formats.
    • Use this code in the PDE to see the list of write formats: println(javax.imageio.ImageIO.getReaderFormatNames());
    • For me it prints: jpg BMP bmp JPG wbmp jpeg png PNG JPEG WBMP GIF gif (note that TIF and TGA are not part of this list and there is in fact code to handle these formats in the save() method itself)
    • For the formats in the list of write formats, the saveImageIO() method is called.
    • In the saveImageIO() method I see code snippets for bmp, jpg, png, but nothing specific for GIF.
    • My guess is that GIF falls through and is handled by line 3160: return javax.imageio.ImageIO.write(bimage, extension, file);
    • This means that a file is in fact saved, but the question is, is this done correctly.
    • I think the underlying problem is that GIF is a file format with limitations, the most important being that a GIF can only store 256 colors (another is that transparancy is binary).
    • To handle GIF correctly (read: most likely in situations when there are more than 256 colors in the image), I believe there would need to be additional code in the saveImageIO() method, which currently isn't there.

    So my conclusion at this time is:

    • The reference is up to date: GIF is not supported
    • The fact that GIF saves instead of trowing an error is a quasi-BUG (that perhaps is allowed consiously as an 'undocumented, unsupported feature' because in some situations it might work).
    • Full support for GIF would be a feature request.
  • Thanks a lot for this extensive answer, amnon! :)

    It's too bad that GIF isn't supported yet since it's necessary to create animated GIFs ... or should one save them in a different format and then convert them manually to GIFs?

  • Answer ✓

    That is definitely a good option. It will ensure you have high quality output, which you can later turn into a GIF animation with all the speed, filesize, quality options you want. For example Photoshop has "save for web" support I believe. Most likely Gimp also has it. And of course there are other image editing and/or (freeware) GIF creation applications.

    Alternatively, you can use the gifAnimation Processing library.

Sign In or Register to comment.