> 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/jpe
g_metadata.html
>
> -phil.


Ok, I'm stuck again. Here's what I have so far...

    public static void main(String[] args)
    {

                //create a colored square
        BufferedImage bi = new BufferedImage(100, 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D biContext = bi.createGraphics();
        biContext.setColor(Color.blue);
        biContext.fillRect(0, 0, 200, 200);

        Iterator i = ImageIO.getImageWritersByFormatName("jpeg");
        //are there any jpeg encoders available?

        if (i.hasNext()) //there's at least one ImageWriter, just use the
first one
        {
            ImageWriter imageWriter = (ImageWriter) i.next();
            //get the param
            ImageWriteParam param = imageWriter.getDefaultWriteParam();
            ImageTypeSpecifier its = new
ImageTypeSpecifier(bi.getColorModel(),bi.getSampleModel());

            //get metadata
            IIOMetadata iomd =
imageWriter.getDefaultImageMetadata(its,param);

            String formatName = "javax_imageio_jpeg_image_1.0";//this is the
DOCTYPE of the metadata we need

            IIOMetadataFormat format = iomd.getMetadataFormat(formatName);

            String[] strings = format.getAttributeNames("app0JFIF");
            //change density to 150DPI   - how?

            for (int s = 0; s < strings.length; s++)
            {
                String string = strings[s];

                System.out.println(string);   //print out the attribute
names for the element I want to change
            }
        }
    }

when I run this method I get this output:

majorVersion
minorVersion
resUnits
Xdensity
Ydensity
thumbWidth
thumbHeight

I want to change the resUnits, Xdensity, and Ydensity values.....but every
class I look at in metadata seems to have protected methods for changing
attributes. I'm stumped. I don't even know how to querry what the current
values for these attributes are.

I want to give resUnits a value of "1" for dots/inch, and give
Xdensity/Ydensity values of 150.

Any clues for me? 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