> This has been addressed to some extent in the past, save for the
> following point:
[quoted text clipped - 13 lines]
> Isn't there a direct way to paint only a specific area inside a
> Graphics object?
you can make following:
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
g2.translate(x, y);
paint(g2);
g2.dispose();
if you need to make this often, then don't create image every time.

Signature
Andrey Kuznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
fahruz@hotmail.com - 13 Jan 2005 03:06 GMT
Thanks for the answer Andrey but this doesn't work. It seems you're
trying to translate the coordinates of the target image's graphics
object whereas it should probably be the jpanel's. Maybe
Graphics2D g2p = (Graphics2D)jpanel.getGraphics();
g2p.translate(x,y);
But then, how to copy the rectangle portion of the jpanel's graphics
into the image's graphics?
I might also point out there was a small mistake in my code example. I
meant to call the jpanel's paint method
BufferedImage image = new BufferedImage(jpanel.getWidth(),
jpanel.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
jpanel.paint(g2); // instead of just paint(g2);
image = image.getSubimage(x, y, width, height);
Thx.
Andrew Thompson - 13 Jan 2005 08:26 GMT
> I might also point out there was a small mistake in my code example.
You might instead post an SSCCE, it will save time.
<http://www.physci.org/codes/sscce.jsp>

Signature
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
fahruz@hotmail.com - 14 Jan 2005 08:11 GMT
You might instead RTTBR (Read The Thread Before Replying), it will save
time. My code is not the problem here. We're looking for efficient ways
to address the issue described in the first question.
Andrew Thompson - 14 Jan 2005 10:12 GMT
> You might instead RTTBR (Read The Thread Before Replying), ..
Many things might happen.
You for example, might quote a little of what you are replying to,
as I have above - to provide context to the reader. Threads from
earlier conversations drop off a lot of servers.
You might even (by use of effective communication) resolve the
technical issue.

Signature
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
Andrey Kuznetsov - 14 Jan 2005 09:47 GMT
> Thanks for the answer Andrey but this doesn't work.
which result you got?
> It seems you're
> trying to translate the coordinates of the target image's graphics
> object whereas it should probably be the jpanel's. Maybe
> Graphics2D g2p = (Graphics2D)jpanel.getGraphics();
> g2p.translate(x,y);
surely this is the wrong way
> But then, how to copy the rectangle portion of the jpanel's graphics
> into the image's graphics?
you can't
> I might also point out there was a small mistake in my code example. I
> meant to call the jpanel's paint method
[quoted text clipped - 4 lines]
> jpanel.paint(g2); // instead of just paint(g2);
> image = image.getSubimage(x, y, width, height);
this is not the problem.

Signature
Andrey Kuznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
Andrey Kuznetsov - 14 Jan 2005 10:47 GMT
> BufferedImage image = new BufferedImage(width, height,
> BufferedImage.TYPE_INT_RGB);
> Graphics2D g2 = image.createGraphics();
> g2.translate(x, y);
> paint(g2);
> g2.dispose();
if it didn't worked, may be you should change this a little:
g2.translate(-x, -y);

Signature
Andrey Kuznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities