lomidien
asked on
Graphics object to image
If I have an image and call .getGraphics() in order to retrieve a graphics context to draw to, how can I draw another graphics on top of it?
For instance, I have an image and I would like to superimpose an image of a component on top of it. I don't see any methods in the api for this direct effect, but I'm sure there must be a way.
Thanks,
David
For instance, I have an image and I would like to superimpose an image of a component on top of it. I don't see any methods in the api for this direct effect, but I'm sure there must be a way.
Thanks,
David
You can simply draw over it
i.e.
1. "I have an image and call .getGraphics()"
2. "... would like to superimpose an image of a component on top of it" - so call drawImage on the Graphics obtained above
1. "I have an image and call .getGraphics()"
2. "... would like to superimpose an image of a component on top of it" - so call drawImage on the Graphics obtained above
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
//unfilteredScreenImage is a BufferedImage
Graphics g1 = unfilteredScreenImage.getG
//gp is a glasspane for a frame which contains some painted graphics
Graphics g2 = gp.getGraphics();
I get an error calling: g1.paint(g2) because it cannot find a method with a graphics object as an argument
Am I overlooking something?
Thanks,
David
That's because Graphics#paint() doesn't exist.... :o\
ASKER
But then how to accomplish the effect?
Perhaps this is stupid enough to work:
Graphics g1 = unfilteredScreenImage.getG raphics();
Graphics g2 = gp.getGraphics();
g1.drawImage( g2, 0, 0, this );
?
Graphics g1 = unfilteredScreenImage.getG
Graphics g2 = gp.getGraphics();
g1.drawImage( g2, 0, 0, this );
?
Sorry, try this instead:
Graphics g2 = gp.getGraphics();
g1.drawImage( unfilteredScreenImage, 0, 0, this );
Graphics g2 = gp.getGraphics();
g1.drawImage( unfilteredScreenImage, 0, 0, this );
Dammit... still wrong. lol.. Before I go any further, can you tell me what class 'gp' instantiates please?
ASKER
Sorry IM, didn't hit refresh to see those responses and in the meantime I solved it via CEHJ's suggestion.
gp is a custom glassPane.
I fixed it by passing the g1 to the paint method of gp.
i.e. gp.paint(g1);
and that did the trick.
Thanks for all the help guys,
David
gp is a custom glassPane.
I fixed it by passing the g1 to the paint method of gp.
i.e. gp.paint(g1);
and that did the trick.
Thanks for all the help guys,
David
Good man. :-)
:-) You caught my slip ;-)