Discussions
Categories
- 197.1K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.7K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 555 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.3K SQL Developer
- 296.3K Development
- 17 Developer Projects
- 139 Programming Languages
- 293K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 158 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 466 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
How to increase Image DPI?

HarshaSK
Member Posts: 84
Hi All,
I increased the DPI of a image to 299.99 DPI from 96 DPI. It displays 299.99 DPI in the image property but it doesnt have any effect on the image clarity. The image is still blur on zoom. How to increase the DPI so that the image clarity increases?
I have used the below logic -
String dotsPerMeter = String.valueOf((int) (300 / 0.0254));//300 is the dpi required
Iterator imageWriters = ImageIO.getImageWritersByFormatName("png");
while (imageWriters.hasNext()) {
ImageWriter iw = (ImageWriter)imageWriters.next();
ImageWriteParam iwp = iw.getDefaultWriteParam();
IIOMetadata metadata = iw.getDefaultImageMetadata(new ImageTypeSpecifier(image), iwp);
String pngFormatName = metadata.getNativeMetadataFormatName();
IIOMetadataNode pngNode =
(IIOMetadataNode) metadata.getAsTree(pngFormatName);
IIOMetadataNode physNode = null;
NodeList childNodes = pngNode.getElementsByTagName("pHYs");
if (childNodes.getLength() == 0) {
physNode = new IIOMetadataNode("pHYs");
pngNode.appendChild(physNode);
} else if (childNodes.getLength() == 1) {
physNode = (IIOMetadataNode) childNodes.item(0);
} else {
throw new IllegalStateException("Don't know what to do with multiple pHYs nodes");
}
physNode.setAttribute("pixelsPerUnitXAxis", dotsPerMeter);
physNode.setAttribute("pixelsPerUnitYAxis", dotsPerMeter);
physNode.setAttribute("unitSpecifier", "meter");
try {
metadata.setFromTree(pngFormatName, pngNode);
IIOImage iioImage = new IIOImage(image, null, metadata);
File file = new File(KIT_ID + "_" + KIT_VER + "_newDPI.png");
ImageOutputStream ios = ImageIO.createImageOutputStream(file);
iw.setOutput(ios);
iw.write(iioImage);
ios.flush();
ios.close();
} catch (Exception e) {
e.printStackTrace();
continue;
}
break;
}
Please someone, help me solve this.
Thanks a ton.
I increased the DPI of a image to 299.99 DPI from 96 DPI. It displays 299.99 DPI in the image property but it doesnt have any effect on the image clarity. The image is still blur on zoom. How to increase the DPI so that the image clarity increases?
I have used the below logic -
String dotsPerMeter = String.valueOf((int) (300 / 0.0254));//300 is the dpi required
Iterator imageWriters = ImageIO.getImageWritersByFormatName("png");
while (imageWriters.hasNext()) {
ImageWriter iw = (ImageWriter)imageWriters.next();
ImageWriteParam iwp = iw.getDefaultWriteParam();
IIOMetadata metadata = iw.getDefaultImageMetadata(new ImageTypeSpecifier(image), iwp);
String pngFormatName = metadata.getNativeMetadataFormatName();
IIOMetadataNode pngNode =
(IIOMetadataNode) metadata.getAsTree(pngFormatName);
IIOMetadataNode physNode = null;
NodeList childNodes = pngNode.getElementsByTagName("pHYs");
if (childNodes.getLength() == 0) {
physNode = new IIOMetadataNode("pHYs");
pngNode.appendChild(physNode);
} else if (childNodes.getLength() == 1) {
physNode = (IIOMetadataNode) childNodes.item(0);
} else {
throw new IllegalStateException("Don't know what to do with multiple pHYs nodes");
}
physNode.setAttribute("pixelsPerUnitXAxis", dotsPerMeter);
physNode.setAttribute("pixelsPerUnitYAxis", dotsPerMeter);
physNode.setAttribute("unitSpecifier", "meter");
try {
metadata.setFromTree(pngFormatName, pngNode);
IIOImage iioImage = new IIOImage(image, null, metadata);
File file = new File(KIT_ID + "_" + KIT_VER + "_newDPI.png");
ImageOutputStream ios = ImageIO.createImageOutputStream(file);
iw.setOutput(ios);
iw.write(iioImage);
ios.flush();
ios.close();
} catch (Exception e) {
e.printStackTrace();
continue;
}
break;
}
Please someone, help me solve this.
Thanks a ton.
Tagged:
Answers
-
>
I increased the DPI of a image to 299.99 DPI from 96 DPI. It displays 299.99 DPI in the image property but it doesnt have any effect on the image clarity. The image is still blur on zoom. How to increase the DPI so that the image clarity increases?
>
Prove that your image actually has more than 96 DIP. You can't get a higher resolution than the image has to begin with so without knowing what the resolution of the original image is there is no way to know if you can change the DPI without blurring things. -
Are you working for the CSI?
-
No i don't work for the CSI.
Ok let me be more clear of my requirement.
I create an image using java code. It basically text, lines, color and borders. When it gets created, its of 96 DPI. My requirement is to retain the size of the image and increase the DPIs to 300 or more so that the clarity of the image is not lost when zoomed.
please suggest me a way to achieve it. -
When it gets created, its of 96 DPI.So change that so when it gets created it is 300 DPI. Afterwards it is too late.
-
Yes, i have tried that using the below method -
private void setDPI(IIOMetadata metadata) throws IIOInvalidTreeException {
// for PNG, it's dots per millimeter
double dotsPerMilli = 1.0 * 300 / 10 / 2.54;
IIOMetadataNode horiz = new IIOMetadataNode("HorizontalPixelSize");
horiz.setAttribute("value", Double.toString(dotsPerMilli));
IIOMetadataNode vert = new IIOMetadataNode("VerticalPixelSize");
vert.setAttribute("value", Double.toString(dotsPerMilli));
IIOMetadataNode dim = new IIOMetadataNode("Dimension");
dim.appendChild(horiz);
dim.appendChild(vert);
IIOMetadataNode root = new IIOMetadataNode("javax_imageio_1.0");
root.appendChild(dim);
metadata.mergeTree("javax_imageio_1.0", root);
}
This method shows the DPI of the image as 299.99, but there is no real impact to the image as it looks. It loses clarity when zoomed. There is no difference between the original one and the modified one.
This discussion has been closed.