简体   繁体   中英

how to reduce the resolution to an image without loose dpi?

I have the following class

public void resize(InputStream input, OutputStream output, int width, int height) throws IOException {
    BufferedImage src = ImageIO.read(input);
    BufferedImage dest = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = dest.createGraphics();

    AffineTransform at = AffineTransform.getScaleInstance((double)width / src.getWidth(), (double)height / src.getHeight());
    g.drawRenderedImage(src, at);
    ImageIO.write(dest, "tif", output);
    output.close();
}

but in the final result, I lose dpi at 1. how i can keep the dpi in the image?

Dpi is abbreviate of dot per inch and backs to the quality of an image. So, when you change the resolution of an image, you'll loose dpi (dot per inch) of the image in the original size of that image (because you loose the quality!). Hence, it's not possible!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM