Solved

BufferedImage widht/height parameters

Posted on 2012-03-21
3
385 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 250 total points
ID: 37747500
Yes, that kind of approach should be ok
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 250 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Receive file in Servlet 1 36
Free Alternative to JIRA 4 58
@SBGen Method 3 25
Securing Jmx Console and web console 2 48
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now