Skip to main content

Svaving image with markings to file

6 replies [Last post]
jam007
Offline
Joined: 2009-11-18

Hi!

I have a JAI image displayed using an extended DisplayJAI, adding mark drawing routines to the paint method, to allow users to draw marks on the image. Now I want to save the image including marks made by the user to a file.
How do I do that?

Anders M
Sweden

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Nidel, Mike

Hi Anders,

Before we can help I have a few questions.

1. How large is the image file that you want to save, in pixels (width and height)?
2. What format do you want to save in?
3. What library or API do you plan to use to save the file? (I recommend ImageIO)

If the image is not very large, this is a relatively easy problem. If it is
larger than a few MB, it might be a little bit more difficult. Particularly if
the entire image does not fit in heap memory at once.

cheers,

Mike

> -----Original Message-----
> From: jai-imageio@javadesktop.org [mailto:jai-imageio@javadesktop.org]
> Sent: Thursday, November 19, 2009 4:57 AM
> To: interest@jai-imageio.dev.java.net
> Subject: [JAI-IMAGEIO] Svaving image with markings to file
>
> Hi!
>
> I have a JAI image displayed using an extended DisplayJAI, adding mark
> drawing routines to the paint method, to allow users to draw marks on
> the image. Now I want to save the image including marks made by the
> user to a file.
> How do I do that?
>
> Anders M
> Sweden
> [Message sent by forum member 'jam007' ]
>
> http://forums.java.net/jive/thread.jspa?messageID=372499
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

jam007
Offline
Joined: 2009-11-18

Thanks for your interest Mike.

1 It´s ca 200 x 200 pixels 256 color image so it´s a small image
2 jpeg will do fine. The picture will (as far as I can see) only be used in documentation afterwards.
3 ImageIO if you recommend it :) Have no particular preference.

Nidel, Mike

OK good. that sounds easy. I assume that in your custom paint()
method you have a list of the graphics that you're drawing. You'll
need to pass that to your output code.

1. Get your image as a BufferedImage instance
2. Get the Graphics2D by calling BufferedImage.createGraphics()
3. Iterate over your graphics, calling Graphics2D.draw() as appropriate.
4. When finished, call Graphics2D.dispose()
5. Call ImageIO.write(), passing in your BufferedImage and the other
arguments as needed

this should get you at least 80% of the way there. Let us know if you
have questions after that.

> -----Original Message-----
> From: jai-imageio@javadesktop.org [mailto:jai-imageio@javadesktop.org]
> Sent: Thursday, November 19, 2009 10:17 AM
> To: interest@jai-imageio.dev.java.net
> Subject: Re: RE: [JAI-IMAGEIO] Svaving image with markings to file
>
> Thanks for your interest Mike.
>
> 1 It´s ca 200 x 200 pixels 256 color image so it´s a small image
> 2 jpeg will do fine. The picture will (as far as I can see) only be
> used in documentation afterwards.
> 3 ImageIO if you recommend it :) Have no particular preference.
> [Message sent by forum member 'jam007' ]
>
> http://forums.java.net/jive/thread.jspa?messageID=372559
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

jam007
Offline
Joined: 2009-11-18

Thanks! I give it a try.

Anders M

jam007
Offline
Joined: 2009-11-18

It worked! Thanks for the help.

Anders M

Nidel, Mike

terrific! glad to assist.

> -----Original Message-----
> From: jai-imageio@javadesktop.org [mailto:jai-imageio@javadesktop.org]
> Sent: Thursday, November 19, 2009 12:53 PM
> To: interest@jai-imageio.dev.java.net
> Subject: Re: RE: RE: [JAI-IMAGEIO] Svaving image with markings to file
>
> It worked! Thanks for the help.
>
> Anders M
> [Message sent by forum member 'jam007' ]
>
> http://forums.java.net/jive/thread.jspa?messageID=372576
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net