Forums Register Login

simple graphics question

+Pie Number of slices to send: Send
is it possble to draw one graphics object on another?

example. pass an object Graphics g... can it draw g onto another Graphics object gg?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
Can you post the code you are using? There are a couple of things I can think of off the top of my head that could cause this, but it would help to see what code you are actually working with...

Could be the type of BufferedImage you are creating... could be caused somewhere in the process of the drawImage (BufferedImage may be one size and drawn on the other graphics context at another...)
+Pie Number of slices to send: Send
Ok.. some background - displayPane object is given a SwitchPermit object when it is created.

Using data in the SwitchPermit object, displayPane creates graphics which it draws on itself and also can create a bufferedImage with the same graphics ( createBufferedImage() ).

This bufferedImage is than passed to a Page object - in order to easily print the different pages.

Page also does some graphics manipulation in its print(). (translating image)

Also - there are some unneccessary fillRect calls, I had some problems with printing large black squares on pages that were not filled with graphics.


( note: this is my first time working with printing, graphics , or bufferedImages - please dont view this as 'the right way' to do things )

displayPane.printPages ( shortened):


displayPane.createBufferedImage:


Page.print:



[ December 22, 2004: Message edited by: Rich Stepanski ]
[ December 22, 2004: Message edited by: Rich Stepanski ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1450 times.
Similar Threads
Disappearing Graphics on panel
paintComponent()
bufferedImage and Graphics2D
Multiline JLabel
Can JPanel's paint() use different Graphics2D objects?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:43:31.