Getting image data using Java 2D API

Hi,

I have an application where I need to collect the following data about an image file. (jpg, gif, or png)

1. Quality of the image in DPI (dots per inch)

2. Size of the image in Pixels (width & height)

3. Converting PNG image to JPEG.

Can I achieve all the above three using Java 2D API?

Any info is appreciated.

Thanks.

[377 byte] By [seanua] at [2007-11-26 16:03:33]
# 1

> Can I achieve all the above three using Java 2D API?

In short - yes, you can do it with Java2D (in most of cases).

> I have an application where I need to collect the

> following data about an image file. (jpg, gif, or

> png)

>

> 1. Quality of the image in DPI (dots per inch)

This is most difficult on your list.

You need to get access to image metadata and find your answer.

Note that for some images there could be more than one dpi in metadata tree (e.g. one per each embeded preview image), so you have to

pick correct one.

Read about using metadate wih ImageIO (javax.imageio.*).

Also, there are some known java2d limitations related to

EXIF support for jpeg. I am not quite sure but it is likely that

for such images you will only get access to limited (if any) metadata.

> 2. Size of the image in Pixels (width & height)

easy.

For instance, use ImageIO.read to get BufferedImage and

request size.

You can also get it from metadata as for step 1,

this way will be more efficient because image will not be actually read to memory and decoded but it is a bit more complicated to implement.

> 3. Converting PNG image to JPEG.

Simplest solution is something like

(note you need to lookup API to correct syntax):

BufferedImage bi = ImageIO.read("my.png");

ImageIO.write(bi, "my.jpg");

neigora at 2007-7-8 22:25:24 > top of Java-index,Security,Cryptography...
# 2
Thank you for the detailed answer. Now I know what to do.
seanua at 2007-7-8 22:25:24 > top of Java-index,Security,Cryptography...