File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Printing hi-res (say, 300 dpi) images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Printing hi-res (say, 300 dpi) images" Watch "Printing hi-res (say, 300 dpi) images" New topic

Printing hi-res (say, 300 dpi) images

dave taubler
Ranch Hand

Joined: May 15, 2001
Posts: 132
I can't seem to find any information online about printing high resolution photos or images from a Java app, and I'm wondering if anyone here as any experience.

In the app I'm working on, printing out 72 dpi images works as expected. Printing out higher res (like 300 dpi) images doesn't--or maybe it does work as expected, but I want to change the behavior . It seems as though Java is still thinking in terms of printing to screen resolution, because when I try to print a 300 dpi image, it will print out the image 4+ times larger than the actual image, with the same "fidelity" as a 72 dpi image. In other words, if an image is 300 dpi, 4 inches x 6 inches, it will print the image as if it was about 16 inches x 24 inches, at 72 dpi.

Obviously, want I want is a photo-quality 4 x 6 image. Anyone know of any way to force Java printing to do that?

Dave Taubler<br />Specializing in <a href="" target="_blank" rel="nofollow">Java and Web Development</a>
H Lander

Joined: Oct 23, 2005
Posts: 15
I have not actually done this, but I read somewhere that you should scale the Graphics Context as displayed below.

Try it and let us know how it worked.

Good Luck,

dave taubler
Ranch Hand

Joined: May 15, 2001
Posts: 132
Hey H Lander,

Thanks for responding. I ultimately tried another (similar) way, basically by using this version of Graphics2D.drawImage:

dx2 and dy2 basically define rectangular bounds that your image must fit into. To do this, you need to know what your target printed size will be, and do a few calculations. My fear was that it would still print out at a crappy, non-photographic-quality resolution, but that doesn't seem to be the case.
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
So basically you need to transform the image such that when printed the increase in size due to increase in DPI will offset the transform arriving at the original size but with an increased DPI?

Putting this one in my list of tricks.
dave taubler
Ranch Hand

Joined: May 15, 2001
Posts: 132
From what I learned (after finding a few things onlnie as well as talking with image gurus at my company) is that DPI, or resolution in general, is not an inherent "property" in an image at all. All the images knows about--short of any metadata that might be stored somewhere--is how many samples (or roughly speaking, "dots") it contains.

If you don't specify otherwise, it seems that Java will draw your image to the printer at a size where 72 of those samples or dots will fit into the space of one inch. However, if you use one of the aforementioned methods to tell Java what size you want the image to be printed at, it will fit all of the samples/dots into the dimension that you specify; thus, if you specify a smaller image size, you get a higher resolution printout.
subject: Printing hi-res (say, 300 dpi) images
It's not a secret anymore!