Link to home
Start Free TrialLog in
Avatar of allelopath
allelopath

asked on

BufferedImage widht/height parameters

I want to create a BufferedImage like so:

BufferedImage myImage = new BufferedImage((int)width, (int)height, BufferedImage.TYPE_INT_RGB);

The difficult is that the width and height I have are in inches, so I need to convert inches to pixels. How do I determine the pixels/inch?
Avatar of allelopath
allelopath

ASKER

I guess something like this:
private static int getPixelsPerInch() {
		
    JFrame myframe = new JFrame("Test");  
    myframe.setSize(20, 20);
    myframe.setVisible(false);

    Toolkit toolkit = myframe.getToolkit();
    int dpi = 0;
    // Next line gets the number of pixels in an inch
    dpi = toolkit.getScreenResolution();

    return dpi;
        
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial