1

i increased the DPI of a image to 299.99 DPI from 96 DPI. But it doesnt have any effect on the image. The image is still blur on zoom. How to increase the DPI so that the image clarity increases?

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;
            }
HarshaSK
  • 39
  • 1
  • 6

1 Answers1

0

Adding Dpi to a blurry picture does not make it sharper, because the pixels of your image just split, but there wont be any more detail created in the image. there are however some algorithms that help make pictures look more sharp.

  • Thank u Tom, the source image has few lines which is displayed like like broken when u zoom. For this reason i want to increase the DPI to 300 so that it looks neat even when u zoom. Can u plz suggest me few methods to achieve this? – HarshaSK Nov 23 '12 at 05:30
  • probably the best i can find http://stackoverflow.com/questions/6575366/how-to-improve-image-quality-in-matlab http://photo.stackexchange.com/questions/12788/is-it-possible-to-increase-the-pixel-density-of-an-image –  Nov 23 '12 at 11:25
  • 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. – HarshaSK Nov 28 '12 at 07:59