It depends on your definition of the term "from the contents of".
The simplest way to get a snapshot of a subrectangle of an existing
image is to simply create a new image and draw the original into the new
one, as in:
// assuming:
Image src;
int subx, suby, subw, subh;
// then execute:
BufferedImage snap =
new BufferedImage(subw, subh, TYPE_INT_RGB);
Graphics2D g2d = snap.createImage();
g2d.drawImage(src, -subx, -suby, null);
g2d.dispose();
// snap is now a snapshot of subx,y,w,h of src
and the "snap" image will now be a snapshot of the contents in that
rectangle (subxywh) of the original "src" image, and it will be a
BufferedImage as you requested. Further rendering on the "src" image
will not affect the contents of the "view" image and vice versa.
If you didn't want a snapshot, I can outline other ways, but I'm
guessing that this is probably what you wanted...?
...jim
[EMAIL PROTECTED] wrote:
I feel fairly stupid asking this question, as it seems like an operation that
should be pretty simple, and it probably is, but for whatever reason I can't
figure out the best way to do it. So I'm sorry in advance. :-)
I'd like to create a new BufferedImage from the contents of a subregion of an
existing java.awt.Image. What is the best, least bloated, least convoluted way
to do this?
Thanks in advance,
Laird
[Message sent by forum member 'ljnelson' (ljnelson)]
http://forums.java.net/jive/thread.jspa?messageID=295189
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".