Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

BufferedImage widht/height parameters

Posted on 2012-03-21
3
Medium Priority
?
423 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

719 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