>  > So, say I have drawn a 100x100 pixel blue square in my Graphics (at 72
>  > DPI)...how do I turn it into a JPEG at 150 DPI?
>  >
>
> I believe you aren't thinking about this right.
> java images, eg buffered images are created in pixels not dpi.
> once you know that the phrase above says you want to create
> information that isn't there, or you want to claim its from a higher
> resolution source than is the fact.

Well I think I was simplifying the issue for discussion; in drawing a square
with a solid color I had the implicit understanding I could easily scale
this to whatever DPI I needed - as a easy case to just get this to work as a
first step. So if I wanted to draw a square on the screen 100 x 100 pixels,
and it was really coming from a 150 DPI square with 200x200 pixels,
obviously I would have to scale that square smaller when I draw it. The JPEG
file I saved would really have to be (about) a 200 x 200 pixel square @ 150
DPI to save that extra density data.

What I will eventually be doing is working with images with a much greater
DPI than the screen, manipulating that data, and saving it in the higher
resolution, and just rendering it to screen at a lower DPI, (or "blowing it
up" so it looks bigger on the screen (in inches) than it really is, to allow
the user to see all the actual detail of the image.)



>
> instead create a BufferedImage image at the pixel dimensions you want
> and you can scale it for on-screen drawing (see Graphics.drawImage(..)
> apis)
>
> Save it for example using
>
> javax.imageio.ImageIO.write(bimg, "jpg", new File("blah.jpg"));
>
> ( I don't know how much easier we could make this!)
>
> Done.

Yea that looks pretty easy, =) and I did see that API yesterday but didn't
know how to deal with the DPI issue.
>
> For extra credit:
>
> Do you really want 150 dpi in the output jpeg? (ie so that viewers would
> also scale it appropriately?)
> If you want to save resolution information then YES you do have to
> do more. Go to the website and locate the imageio guide in pdf, ps or
> html and check out the JPEG metadata spec
> http://java.sun.com/j2se/1.4.1/docs/api/javax/imageio/metadata/doc
> -files/jpeg_metadata.html

Ok, that looks promising, I'll take a look. I had planned on using the
com.sun.image.codec.jpeg.JPEGEncodeParam's setDensityUnit() and
setXDensity(), setYDensity(), but as the docs clearly warn, these classes
aren't part of the Java API so I knew this couldn't be the permanent
solution. So I'll take a look at the metadata doc and see what I can do with
that and get back to you.

Thanks!

Rob

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to