Let me start off with I have no code and I have no idea what I am suppose to do. Apparently the information is stored in the meta data of the .png file. I figure this should not be so hard to do, but it is turning out to be a challenge.
The only thing that looks somewhat useful is the following post here at stack overflow.
How to set DPI information in an image?
However I have tried to use the code that was provided and the websites that were provided to do such things and have achieved nothing.
When I try to use the Iterator, like below, I get an error with both the iw.hasNext() and the iw.next().
Errors are:
- The method hasNext() is undefined for the type HTMLDocument.Iterator
Type mismatch: cannot convert from void to ImageWriter
for (Iterator iw = (Iterator) ImageIO.getImageWritersByFormatName(formatName); iw.hasNext;) { ImageWriter writer = iw.next();
My question is, where do I start and what do I need to be looking for? Are there any examples that you know of or have you done this yourself?
One a side note my questions about the "How to set DPI information in an image?" post are this...
- Why is it then when I use the Iterator like he does, I get errors?
- What is "INCH_2_CM" suppose to mean / be?
The way I changed his code is below...
for (Iterator iw = (Iterator) ImageIO.getImageWritersByFormatName(formatName); iw.hasNext();) {
ImageWriter writer = iw.next();
ImageWriteParam writeParam = writer.getDefaultWriteParam();
ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
if (metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) {
continue;
}
setDPI(metadata);
final ImageOutputStream stream = ImageIO.createImageOutputStream(output);
try {
writer.setOutput(stream);
writer.write(metadata, new IIOImage(gridImage, null, metadata), writeParam);
} finally {
stream.close();
}
break;
}