Skip to main content

Re: Re: [JAI] problems drawing on to a buffered image

1 reply [Last post]
Anonymous

Hello

Thanks for that - the TiledImage seems to help quite a lot because the source image is reasonably large.

The BufferedImage option, passing a ColorModel might help with the next part of the problem. My source image was loaded from 1bit black and white imagery and I need to draw a some colour on top of it. How do I convert the SampleModel and ColorModel to achieve this ? There seem to be examples in the FAQ about reducing image depth and creating greyscale but not the reverse.

At certain times, I think I struggle at the conceptual level with JAI. I understand certain areas of JAI but getting into new concepts can be quite difficult. Is there a high level document or class diagram ?

Thanks

Chris
>
> From: Brian Burkhalter
> Date: 2005/05/05 Thu PM 03:57:52 GMT
> To: Java Advanced Imaging discussion list ,
> christopher.faulkner@ntlworld.com
> Subject: Re: [JAI] problems drawing on to a buffered image
>
> Chris,
>
> Per the documentation here
>
> http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/PlanarImage.html#getAsBufferedImage(java.awt.Rectangle,%20java.awt.image.ColorModel)
>
> the BufferedImage is a *copy* of the PlanarImage. I think there are two good
> options for what you want to do:
>
> 1) Save the BufferedImage "bi" instead.
> 2) Create a TiledImage using this constructor
>
> http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/TiledImage.html#TiledImage(java.awt.image.RenderedImage,
> boolean)
>
> as
>
> TiledImage ti = new TiledImage(img, true);
>
> and replace the 'bi' in your code with 'ti'. The second parameter of the
> constructor causes 'img' to be overwritten so you may save either 'img' or
> 'ti'.
>
> Brian
>
> On Thu, 5 May 2005 christopher.faulkner@ntlworld.com wrote:
>
> > Hello all
> >
> > I have been using JAI for a while now and am successfully using it to crop / scale and tile maps together, mainly from TIFFs.
> >
> > I would now like to draw some lines and text on top of it. I followed a tutorial I found on the JAI website.
> >
> > Basically, the code goes like this.
> >
> > img is a PlanarImage
> >
> >
> > BufferedImage bi = img.getAsBufferedImage();
> > Graphics2D big = bi.createGraphics();
> >
> > big.setColor(Color.BLACK);
> > float dash1[] = {10.0f};
> > BasicStroke bs = new BasicStroke(5.0f, BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
> > big.setStroke(bs);
> > Line2D line = new Line2D.Float(20.0f, 10.0f, 1000.0f, 1000.0f);
> > big.draw(line);
> >
> > big.drawString("BufferedImage", 4, 12);
> > big.drawLine(202,202,202,2000);
> >
> > So I am taking the img, creating a BufferedImage and then a Graphics2D object into which I draw some lines and text.
> >
> > When I encode the img as a JPEG, nothing appears, other than the input imagery which went into the initial PlanarImage.
> >
> > What am I missing ? Do I have to save the BufferedImage / Graphic2D contents back into the PlanarImage (img) and if so how ?
> >
> > Thanks
> >
> > Chris
> >
> > -----------------------------------------
> > Email sent from www.ntlworld.com
> > virus-checked using mcAfee(R) Software
> > visit www.ntlworld.com/security for more information
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> > For additional commands, e-mail: interest-help@jai.dev.java.net
> >
> >
>
> ----------------
> Brian Burkhalter
> Advanced Development, Graphics and Media
> Software Chief Technology Office
> Sun Microsystems, Inc.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This email message is for the sole use of the intended recipient(s)
> and may contain confidential and privileged information. Any
> unauthorized review, use, disclosure or distribution is prohibited.
> If you are not the intended recipient, please contact the sender by
> reply email and destroy all copies of the original message.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>

-----------------------------------------
Email sent from www.ntlworld.com
virus-checked using McAfee(R) Software
visit www.ntlworld.com/security for more information

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bpb
Offline
Joined: 2004-06-23
Points: 0

Chris,

Glad to have been of help.

If you want to convert from 1-bit data to a higher bit depth, you might be able to use for example "Format" to go to grayscale or "Lookup" to go to RGB.

As to the docs, there is no class diagram. There is more documentation listed on the "JAI Utilities" page that might be of use.

Brian

> Hello
>
> Thanks for that - the TiledImage seems to help quite
> a lot because the source image is reasonably large.
>
> The BufferedImage option, passing a ColorModel might
> help with the next part of the problem. My source
> image was loaded from 1bit black and white imagery
> and I need to draw a some colour on top of it. How do
> I convert the SampleModel and ColorModel to achieve
> this ? There seem to be examples in the FAQ about
> reducing image depth and creating greyscale but not
> the reverse.
>
> At certain times, I think I struggle at the
> conceptual level with JAI. I understand certain areas
> of JAI but getting into new concepts can be quite
> difficult. Is there a high level document or class
> diagram ?
>
> Thanks
>
> Chris