• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

simple graphics question

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rich Stepanski
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic