A question about ImageIO

2 views
Skip to first unread message

sunng

unread,
Jul 30, 2007, 11:46:26 PM7/30/07
to V2 Whiteboard
in function Whiteboard.releasedImage(), the method of reading image
file is:

File file = chooser.getSelectedFile();
lastDir = file.getParentFile();

FileInputStream in = new FileInputStream(file);
JPEGImageDecoder decoder =
JPEGCodec.createJPEGDecoder(in);

SVGImage image = new SVGImage(id(), drawX, drawY,
originWidth, originHeight, decoder.decodeAsBufferedImage(), s2w);
appendAndSend(image);
in.close();

but this method can only read jpeg image file, If I want to read
various type of image, is the following code better?

File file = chooser.getSelectedFile();
lastDir = file.getParentFile();

SVGImage image = new SVGImage(id(), drawX, drawY,
originWidth, originHeight, ImageIO.read(file), s2w);
appendAndSend(image);
}

larry sherrill

unread,
Jul 31, 2007, 4:57:51 PM7/31/07
to V2 Whiteboard
Thanks a lot, Sunng. It looks that could open up a lot of different
image types for the whiteboard. We'll have to investigate how to
integrate this because we base64 the image for shipment across the
wire and expect everything to be jpeg on the receiving side, if I
remember correctly. But I don't think it will take too much to use
this technique. It will probably be in version 0.0.4 which we will
begin finalizing shortly.

Thanks again for finding that!
Larry

larry sherrill

unread,
Sep 5, 2007, 5:17:15 PM9/5/07
to V2 Whiteboard
Hello Sunng,

Using your code as a model, I updated the subversion trunk with the
ability open a variety of image types. The acceptable image types
depends on the operating system (using
ImageIO.getReaderFormatNames()).

On my mac it can read images with type: bmp, gif, jpeg, jpg, png, and
tiff.

On my windows machine it can read: bmp, gif, jpeg, jpg, and png.

Thanks again for your help,
Larry

Reply all
Reply to author
Forward
0 new messages