aspose file tools*
The moose likes Game Development and the fly likes simple graphics question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "simple graphics question" Watch "simple graphics question" New topic
Author

simple graphics question

Rich Stepanski
Ranch Hand

Joined: Aug 24, 2004
Posts: 59
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?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Rich Stepanski
Ranch Hand

Joined: Aug 24, 2004
Posts: 59
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 ]
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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...)
Rich Stepanski
Ranch Hand

Joined: Aug 24, 2004
Posts: 59
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 ]
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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.
Rich Stepanski
Ranch Hand

Joined: Aug 24, 2004
Posts: 59
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simple graphics question
 
Similar Threads
Multiline JLabel
bufferedImage and Graphics2D
Can JPanel's paint() use different Graphics2D objects?
paintComponent()
Disappearing Graphics on panel