• Post Reply Bookmark Topic Watch Topic
  • New Topic

Image Resolution  RSS feed

 
Mark Newton
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm sure that this is a relatively simple question, and many others must have faced it, but I can't find anything useful anywhere online - I'm sure I'm searching for the wrong thing, but hopefully someone can point me in a sensible direction.

Essentially I'm trying to obtain an image (GIF, JPEG or PNG ideally) from a component, but with a resolution of 300dpi (for printing) rather than the 72dpi that I have currently.

I'm pretty poor on graphics stuff, so apologies if this is badly described, most of what I've got so far is pieced together from various other sources.

I have a BufferedImage which is created with a JComponent.print() call, in short:



(EDIT: should have mentioned that 'graph' is the component, but that's probably obvious )

Doing this, and simply passing the image to works, but gives me an image with a resolution of 72dpi, which is far too poor for good quality printing.

The component has the ability to scale itself, so by scaling it (by 4x), then doing the above code, and writing the image file, I get a larger image file, still at 72dpi (unsurprisingly). I can then open the image in Photoshop, and increase the resolution to 300dpi, without resampling, which reduces the size of the image in proportion, and this gives me what I'm looking for. The question: how to do this in code, so that the image I export has my original dimensions, but at 300dpi?
[ August 14, 2006: Message edited by: David Payne ]
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The resolution is completely irrelevant to the image, it's solely used when printing.
By just increasing the resolution you get the desired effect, but of course the SIZE it will print at will be lower.

To increase that you will need to increase the width and height of the image to match the size you want to print with the resolution you want to print at.

I can't quickly find a method to set the dpi count using Java but I assume it would be available (though maybe in the printing API rather than the imaging API as it is solely useful for printing).
 
Mark Newton
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for that, I'd kind of come to the same conclusion (although you phrased it far more concisely!)

Essentially, in case there's anyone else struggling with the same problem - I'm simply writing a bigger version of the image, which gives me more pixels, so I can use higher resolution (more dpi), and so obviously a smaller physical size on paper. When I print something (and I'm not sure what, but for now it doesn't really matter) is scaling the image to fit paper - I'm guessing it could be the SimpleDoc object - and it prints just fine.

My only remaining problem (for which I'm coming to the conclusion that there might be no solution) is how to store either the physical dimensions or the resolution (the same thing, really) along with the image in a file. When I write the image it doesn't have that data, and Photoshop assumes it's 72dpi, but I can change the setting in Photoshop to 300dpi and save, and when I re-open the image, it still knows that I want the image at 300dpi. Presumably there's some kind of header to the file that contains this information - if anyone knows how to write to that header, it would be most helpful!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll probably need to modify the metadata in the image, because the DPI value is nothing more than a value in the header of the file (i.e., metadata).

The ImageIO API has a subpackage javax.imageio.metadata which allows you to do things with the metadata of images.

I can't tell you in detail how it works because I've never used it before myself, but at least that's probably what you should be looking at.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!