Solved

BufferedImage widht/height parameters

Posted on 2012-03-21
3
401 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fibonacci ten numbers 4 54
jdbc error in jsp application 20 73
hibernate example issues from command prompt 10 64
Desingning Refactoring existing code 2 31
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…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

756 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