> 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.

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.

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

-phil.

Rob Ross wrote:
Can someone give me some pointers on how I go about creating a simple JPEG
image and saving it to a file?

I want to be able to draw a simple square with a given width/height in
pixels, filled with a solid color given by a RGB value, rendered at 150

DPI.



1) create a new image object
2) get the graphics of the object
3) draw my square in my color
4) convert the image into a JPEG with the right parameters (especially the
DPI)
5) save it to a file.



Ok I have figured out how to do steps 1-3. But I don't know if I have to do something special when I draw into the Graphics2D so that later when I save it as a JPEG, I can get my resolution of 150 DPI, which is more than the standard ~72 DPI of a screen-drawn image.

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?

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".

=========================================================================== 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