Skip to main content

[JAI] Save jpeg with specific resolution

8 replies [Last post]
Anonymous

Hi,

I have to load a jpeg image, make some changes to it using JAI and then save
it to a file with the same resolution it has at the beginning.
If I save it with filestore descriptor the resolution is always 72 dpi. I
solved this problem using
com.sun.image.codec.jpeg package, but I have to encode a BufferedImage
instead of a PlanarImage. This makes my application slower when
the image has many pixels.

Does anybody know how to save a jpeg image with a specific resolution using
JAI?

Thanks in advance,

Bego

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Brian Burkhalter

I don't think this is possible using the codec supplied with JAI in the
com.sun.media.jai.codec package. You can do it using the JPEG writer plug-in
in Java Image I/O javax.imageio. In that case you would supply a metadata tree
to the JPEG ImageWriter. See

http://java.sun.com/j2se/1.5.0/docs/api/javax/imageio/plugins/jpeg/packa...

for more information.

Note that this will work only with the JPEG writer in J2SE, not the one in
JAI-Image I/O Tools (com.sun.media.imageio).

Brian

On Mon, 4 Jul 2005, Bego M. C. wrote:

> I have to load a jpeg image, make some changes to it using JAI and then save
> it to a file with the same resolution it has at the beginning.
> If I save it with filestore descriptor the resolution is always 72 dpi. I
> solved this problem using
> com.sun.image.codec.jpeg package, but I have to encode a BufferedImage
> instead of a PlanarImage. This makes my application slower when
> the image has many pixels.
>
> Does anybody know how to save a jpeg image with a specific resolution using
> JAI?

----------------
Brian Burkhalter
Advanced Development/Media & Entertainment
Market Development Engineering
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

aadil
Offline
Joined: 2006-02-14
Points: 0

hi ,
I have the same question for a tiff image.

I need to know hwo to get the dpi of my cirrent image.

i have a method which takes in vertical and horizontal dpi and sets it for the final image.

Please guide

Aadil

Brian Burkhalter

If you are using JAI you can get the pertinent TIFF field objects from the
TIFFDirectory object which is attached to the image as a property. See the
javadoc for javax.media.jai.operator.TIFFDescriptor.

If you are using JAI-Image I/O Tools you can grab either the native TIFF
metadata XML tree or the generic metadata tree: both contain the resolution.
The mapping between standard and native image metadata is documented in the
package documentation of com.sun.media.imageio.plugins.tiff.

Brian

On Fri, 23 Sep 2005, jai-interest@javadesktop.org wrote:

> hi ,
> I have the same question for a tiff image.
>
> I need to know hwo to get the dpi of my cirrent image.
>
> i have a method which takes in vertical and horizontal dpi and sets it for the final image.
>
>
> Please guide
>
> Aadil
> ---
> [Message sent by forum member 'aadil' (aadil)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=115216&#115216
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Advanced Development/Media & Entertainment
Market Development Engineering
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

aadil
Offline
Joined: 2006-02-14
Points: 0

Thanks brian for your prompt response.I ll certainly look into what u have said, right away.

Thanks
Aadil

aadil
Offline
Joined: 2006-02-14
Points: 0

hi brian,

-------------------
this.inputImage = (PlanarImage)JAI.create("fileload", filename);
TIFFDirectory dir = (TIFFDirectory)this.inputImage.getProperty("tiff_directory");
-------------------
Above is the patch of code where i am loading my image.
I guess this is what you were talking about i create an object of TIFFDirectory and then get the prooeprty followed by getFields.
But i am not sure how i would proceed from this fields step.

Thanks

Aadil

Brian Burkhalter

Please refer to

http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/co...
http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/co...

and the TIFF 6 specification for which a link is given here

http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/ja...

Brian

On Fri, 23 Sep 2005, jai-interest@javadesktop.org wrote:

> hi brian,
>
> -------------------
> this.inputImage = (PlanarImage)JAI.create("fileload", filename);
> TIFFDirectory dir = (TIFFDirectory)this.inputImage.getProperty("tiff_directory");
> -------------------
> Above is the patch of code where i am loading my image.
> I guess this is what you were talking about i create an object of TIFFDirectory and then get the prooeprty followed by getFields.
> But i am not sure how i would proceed from this fields step.
>
> Thanks
>
> Aadil
> ---
> [Message sent by forum member 'aadil' (aadil)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=115233&#115233
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Advanced Development/Media & Entertainment
Market Development Engineering
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

aadil
Offline
Joined: 2006-02-14
Points: 0

hi brian ,
Following your explanantion for jpeg images i came down to this patch of code

public void savejpgimage1()
{
try {
java.io.File file4 = new java.io.File("C:\\testimg","altrenate.jpg");
RenderedImage rendImage = this.inputImage;
ImageOutputStream ios = ImageIO.createImageOutputStream(file4);
ImageWriter writer = null;
Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
if (iter.hasNext()) {
writer = (ImageWriter)iter.next();
}
ImageTypeSpecifier ss = new ImageTypeSpecifier(this.inputImage);
writer.setOutput(ios);
ImageWriteParam iwparam = writer.getDefaultWriteParam();
JPEGImageWriteParam iwparam1 =
(JPEGImageWriteParam) writer.getDefaultWriteParam();
iwparam1.setCompressionMode(ImageWriteParam.MODE_COPY_FROM_METADATA);
IIOMetadata ff ;
ff = writer.getDefaultImageMetadata(ss,iwparam1);
writer.write(ff, new IIOImage(rendImage, null, null), iwparam1);
ios.flush();
writer.dispose();
ios.close();

} catch (IOException e) {
e.printStackTrace();

}

}
----------------------------

I couldnt figure how i would get hold of the tree structure which would be passed to my writer.

I really appreciate your guidance i got my tiff issues resolved.

Thanks

Brian Burkhalter

On Mon, 26 Sep 2005, jai-interest@javadesktop.org wrote:

> I couldnt figure how i would get hold of the tree structure which would be passed to my writer.

http://java.sun.com/j2se/1.5.0/docs/api/javax/imageio/ImageReader.html#getStreamMetadata()
http://java.sun.com/j2se/1.5.0/docs/api/javax/imageio/ImageReader.html#getImageMetadata(int)
http://java.sun.com/j2se/1.5.0/docs/api/javax/imageio/ImageReader.html#getImageMetadata(int,%20java.lang.String,%20java.util.Set)

> I really appreciate your guidance i got my tiff issues resolved.

If you've not yet read

http://java.sun.com/j2se/1.5.0/docs/guide/imageio/index.html

I would suggest doing so.

Brian

----------------
Brian Burkhalter
Advanced Development/Media & Entertainment
Market Development Engineering
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net