-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
5.0
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05)
Java HotSpot(TM) Client VM (build 1.5.0_13-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
JPEG files include a JFIF header which indicates the density and density mode of the image. For example, we could specify a 300 DPI image via the metadata by setting the Xdensity attribute to 300, the Ydensity attribute to 300, and the resMode to 1 (density is in dots per inch). However, JPEGImageWriter is apparently ignoring these settings when the metadata is specified.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the program included with this report, using any JPG file as the first argument, and a file to write to as the second argument.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When viewing the output file, the viewer should tell you what the DPI of the image is, and it should be 300 dpi.
ACTUAL -
The actual DPI of the output image is always the default when no density is specified: 72 dpi.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Iterator;
import javax.imageio.*;
import javax.imageio.metadata.*;
import javax.imageio.stream.*;
import org.w3c.dom.Element;
public class SetDPI
{
public static void main(String[] args) throws Exception
{
File infile = new File(args[0]);
File outfile = new File(args[1]);
FileImageInputStream in = new FileImageInputStream(infile);
Iterator<ImageReader> iterator = ImageIO.getImageReaders(in);
ImageReader reader = iterator.next();
reader.setInput(in);
IIOMetadata data = reader.getImageMetadata(0);
// metadata format names are: javax_imageio_jpeg_image_1.0 or javax_imageio_1.0
Element tree = (Element)data.getAsTree("javax_imageio_jpeg_image_1.0");
Element jfif = (Element)tree.getElementsByTagName("app0JFIF").item(0);
String dpiX = jfif.getAttribute("Xdensity");
String dpiY = jfif.getAttribute("Ydensity");
System.out.println(" Density of source is " + dpiX + "x" + dpiY);
BufferedImage image = ImageIO.read(infile);
ImageWriter writer = ImageIO.getImageWriter(reader);
System.out.println("Writer class is " + writer.getClass());
FileImageOutputStream out = new FileImageOutputStream(outfile);
writer.setOutput(out);
ImageWriteParam writeParams = writer.getDefaultWriteParam();
writeParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
writeParams.setCompressionQuality(0.75f);
data = writer.getDefaultImageMetadata(new ImageTypeSpecifier(image), writeParams);
tree = (Element)data.getAsTree("javax_imageio_jpeg_image_1.0");
jfif = (Element)tree.getElementsByTagName("app0JFIF").item(0);
jfif.setAttribute("Xdensity", dpiX);
jfif.setAttribute("Ydensity", dpiY);
jfif.setAttribute("resUnits", "1"); // density is dots per inch
writer.write(data, new IIOImage(image, null, null), writeParams);
in.close();
out.close();
}
}
---------- END SOURCE ----------
java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05)
Java HotSpot(TM) Client VM (build 1.5.0_13-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
JPEG files include a JFIF header which indicates the density and density mode of the image. For example, we could specify a 300 DPI image via the metadata by setting the Xdensity attribute to 300, the Ydensity attribute to 300, and the resMode to 1 (density is in dots per inch). However, JPEGImageWriter is apparently ignoring these settings when the metadata is specified.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the program included with this report, using any JPG file as the first argument, and a file to write to as the second argument.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When viewing the output file, the viewer should tell you what the DPI of the image is, and it should be 300 dpi.
ACTUAL -
The actual DPI of the output image is always the default when no density is specified: 72 dpi.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Iterator;
import javax.imageio.*;
import javax.imageio.metadata.*;
import javax.imageio.stream.*;
import org.w3c.dom.Element;
public class SetDPI
{
public static void main(String[] args) throws Exception
{
File infile = new File(args[0]);
File outfile = new File(args[1]);
FileImageInputStream in = new FileImageInputStream(infile);
Iterator<ImageReader> iterator = ImageIO.getImageReaders(in);
ImageReader reader = iterator.next();
reader.setInput(in);
IIOMetadata data = reader.getImageMetadata(0);
// metadata format names are: javax_imageio_jpeg_image_1.0 or javax_imageio_1.0
Element tree = (Element)data.getAsTree("javax_imageio_jpeg_image_1.0");
Element jfif = (Element)tree.getElementsByTagName("app0JFIF").item(0);
String dpiX = jfif.getAttribute("Xdensity");
String dpiY = jfif.getAttribute("Ydensity");
System.out.println(" Density of source is " + dpiX + "x" + dpiY);
BufferedImage image = ImageIO.read(infile);
ImageWriter writer = ImageIO.getImageWriter(reader);
System.out.println("Writer class is " + writer.getClass());
FileImageOutputStream out = new FileImageOutputStream(outfile);
writer.setOutput(out);
ImageWriteParam writeParams = writer.getDefaultWriteParam();
writeParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
writeParams.setCompressionQuality(0.75f);
data = writer.getDefaultImageMetadata(new ImageTypeSpecifier(image), writeParams);
tree = (Element)data.getAsTree("javax_imageio_jpeg_image_1.0");
jfif = (Element)tree.getElementsByTagName("app0JFIF").item(0);
jfif.setAttribute("Xdensity", dpiX);
jfif.setAttribute("Ydensity", dpiY);
jfif.setAttribute("resUnits", "1"); // density is dots per inch
writer.write(data, new IIOImage(image, null, null), writeParams);
in.close();
out.close();
}
}
---------- END SOURCE ----------