0

I've been searching for some solutions from the internet yet I still haven't found an answer to my problem.

I've been working or doing a program that would get an image file from my PC then will be edited using Java Graphics to add some text/object/etc. After that, Java ImageIO will save the newly modified image.

So far, I was able to do it nicely but I got a problem about the size of the image. The original image and the modified image didn't have the same size.

The original is a 2x3inches-image while the modified one which supposedly have 2x3inches too sadly got 8x14inches. So, it has gone BIGGER than the original one.

What is the solution/code that would give me an output of 2x3inches-image which will still have a 'nice quality'?

UPDATE:

So, here's the code I used.

public Picture(String filename) {
    try {
        File file = new File("originalpic.jpg");
        image = ImageIO.read(file);
        width  = image.getWidth();
    }
    catch (IOException e) {
        throw new RuntimeException("Could not open file: " + filename);
    }
}

private void write(int id) {
    try {
        ImageIO.write(image, "jpg", new File("newpic.jpg"));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

2nd UPDATE:

I now know what's the problem of the new image. As I check it from Photoshop, It has a different image resolution compared to the original one. The original has a 300 pixels/inch while the new image has a 72 pixels/inch resolution.

How will I be able to change the resolution using Java?

GM-Xile GM-Xile
  • 321
  • 1
  • 8
  • 21
  • 3
    possible duplicate of [ImageIO saves back to original size](http://stackoverflow.com/questions/17616528/imageio-saves-back-to-original-size) – johnchen902 Jul 14 '13 at 06:10
  • Duplicate of [How to set DPI information in an image?](http://stackoverflow.com/questions/321736/how-to-set-dpi-information-in-an-image) – Chase Jul 14 '13 at 07:09

0 Answers0