Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

BufferedImage widht/height parameters

Posted on 2012-03-21
3
Medium Priority
?
429 Views
Last Modified: 2012-03-21
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?
0
Comment
Question by:allelopath
3 Comments
 
LVL 1

Author Comment

by:allelopath
ID: 37747408
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

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1000 total points
ID: 37747500
Yes, that kind of approach should be ok
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 1000 total points
ID: 37748219
Theere was a number of dscussions of that question of how to get reliavble screen resolution  on stackoverflow
without much convincing results though:

http://stackoverflow.com/questions/4707756/how-to-correctly-detect-dpi-of-display-with-java

http://stackoverflow.com/questions/6544510/how-to-get-the-screen-dpi-in-java
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question