Skip to main content

[JAI] problems drawing on to a buffered image

1 reply [Last post]
Anonymous

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

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Marco Sambin - NeoLogica

Dear Christopher,

when you call the getAsBufferedImage() method on your "img" PlanarImage, you
obtain a "snapshot" copy of your current image. If you have a rendering
chain (i.e., your PlanarImage is actually a RenderedOp), then the
getAsBufferedImage() method will force a rendering of the complete operators
chain and of all tiles in your image.

When you perform modifications on the BufferedImage, you are not affecting
the original PlanarImage or rendering chain.

If you want to obtain a new PlanaImage from the modified BufferedImage, you
can do it with the following code:

PlanarImage modImg = PlanarImage.wrapRenderedImage(bi);

Then you can use your new "modImg" with JAI's "store" or "ImageWrite"
operators.

Hope it helps,

Marco.

-----Original Message-----
From: christopher.faulkner@ntlworld.com
[mailto:christopher.faulkner@ntlworld.com]
Sent: giovedì 5 maggio 2005 9.44
To: interest@jai.dev.java.net
Subject: [JAI] problems drawing on to a buffered image

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

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