You can, but it's a little more involved... What you can do is use a BufferedImage for the background image and getGraphics() from it to get a Graphics reference. You then use that Graphics reference to draw to the image. Then in another Graphics object (from another image or a component) you can do a drawImage() to "paste" the original BufferedImage into the background. Then you can draw on top of the previous image using the current Graphics object.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Aug 24, 2004
The bufferedImage worked well and I was able to do what I needed. However, using the bufferedImage seems to reduce my graphic quality.
When I drawImage() the bufferedImage to the other graphics object the quality is reduced and all text becomes blocky. Is there anyway around this?
The end result is an object being passed graphics and than printing them, so the quality is an issue. Thanks. [ December 22, 2004: Message edited by: Rich Stepanski ]
I don't see anything currently that would cause the reduced graphics quality... the scaling of the images that are commented out in the print() method could have caused that though.
It could be that printing is handled stuff differently, too. It's the difference between vector and raster images... vector images are basically instructions on how to reproduce the image. The image can be scaled with no loss of detail or other artifacts, and printers can handle this well. Raster images are basically just a collection of colored pixels, and artifacts will appear if they are scaled. Not sure if the Java implementation of printing components uses a vector way of printing components normally, but using the BufferedImage would change the image to be a raster image. This also might be a cause, but I'd have to do some digging to see how components handle printing to see if the vector/raster thing is true.
Joined: Aug 24, 2004
I'll look into it also.
I was originally printing from the displayPane object - and passing the graphics object in its print() right to paint(). The graphics in print() refers to the actual printing graphics. That had the highest quality - if that helps any. Thanks though.