O
OtisUsenet
Hello,
I am trying to compose some images....
First I create a BufferedImage to serve as the background.
Then I load an Image from the disk, and try drawing it on the
BufferedImage.
Unfortunately, I am having problems getting my image to render using
drawImage(Image, int, int, ImageObserver) method in
java.awt.Graphics2D.
I am doing this in a server-side component, and not in an AWT or Swing
app.
My code:
BufferedImage image = new BufferedImage(100, 100,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics();
// load image from disk (this returns Image that is != null)
Image topImage = Toolkit.getDefaultToolkit().createImage("/tmp/myimage.png");
g2d.drawImage(topImage, 10, 10, Color.red, null);
g2d.dispose();
When I save this image to a disk the topImage is not shown.
If, instead, I write some text over my BufferedImate, like this:
g2d.drawString("Hello World", 10, 10);
This works.
I suspect that g2d.drawImage(topImage, 10, 10, Color.red, null); does
not work because the last parameter (ImageObserver interface) is null.
But what implementation of ImageObserver interface should I be using
in a server-side app?
All examples I have seen deal with images in AWT and Swing components,
which all inherit Component, and thus can use 'this' for the last
parameter, since Component implements ImageObserver.
Any help would be much appreciated.
Thank you!
I am trying to compose some images....
First I create a BufferedImage to serve as the background.
Then I load an Image from the disk, and try drawing it on the
BufferedImage.
Unfortunately, I am having problems getting my image to render using
drawImage(Image, int, int, ImageObserver) method in
java.awt.Graphics2D.
I am doing this in a server-side component, and not in an AWT or Swing
app.
My code:
BufferedImage image = new BufferedImage(100, 100,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics();
// load image from disk (this returns Image that is != null)
Image topImage = Toolkit.getDefaultToolkit().createImage("/tmp/myimage.png");
g2d.drawImage(topImage, 10, 10, Color.red, null);
g2d.dispose();
When I save this image to a disk the topImage is not shown.
If, instead, I write some text over my BufferedImate, like this:
g2d.drawString("Hello World", 10, 10);
This works.
I suspect that g2d.drawImage(topImage, 10, 10, Color.red, null); does
not work because the last parameter (ImageObserver interface) is null.
But what implementation of ImageObserver interface should I be using
in a server-side app?
All examples I have seen deal with images in AWT and Swing components,
which all inherit Component, and thus can use 'this' for the last
parameter, since Component implements ImageObserver.
Any help would be much appreciated.
Thank you!