Re: [JAVA2D] Copying a portion of an Image?
uhhh Maybe you meant: BufferedImage snap = new BufferedImage(subw, subh, TYPE_INT_RGB); >>> Graphics2D g2d = snap.createGraphics(); Jim Graham wrote: Yes, if you want alpha you should pass in TYPE_INT_ARGB. Note that the default compositing mode of the freshly retrieved graphics object is SRC_OVER. The code sample still works fine since the newly constructed image is all 0's (transparent pixels) so copying your source image "over" the fully transparent image works just fine. But, if you try to reuse the image and copy a different section of the source image into it at a later stage then you might want to do the image copy using "g2d.setComposite(AlphaComposite.SRC)"... ...jim [EMAIL PROTECTED] wrote: // 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 OK; thanks. If you didn't want a snapshot, I can outline other ways, but I'm guessing that this is probably what you wanted...? Yep. What allowed you to know that TYPE_INT_RGB was the correct parameter to pass in the BufferedImage constructor? If it helps, I know that the source image often has an alpha value set. Would I use TYPE_INT_RGBA in this case? Thanks again for helping this newbie out. Best, Laird [Message sent by forum member 'ljnelson' (ljnelson)] http://forums.java.net/jive/thread.jspa?messageID=295232 === 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". === 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".
Re: [JAVA2D] Copying a portion of an Image?
Yes, if you want alpha you should pass in TYPE_INT_ARGB. Note that the default compositing mode of the freshly retrieved graphics object is SRC_OVER. The code sample still works fine since the newly constructed image is all 0's (transparent pixels) so copying your source image "over" the fully transparent image works just fine. But, if you try to reuse the image and copy a different section of the source image into it at a later stage then you might want to do the image copy using "g2d.setComposite(AlphaComposite.SRC)"... ...jim [EMAIL PROTECTED] wrote: // 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 OK; thanks. If you didn't want a snapshot, I can outline other ways, but I'm guessing that this is probably what you wanted...? Yep. What allowed you to know that TYPE_INT_RGB was the correct parameter to pass in the BufferedImage constructor? If it helps, I know that the source image often has an alpha value set. Would I use TYPE_INT_RGBA in this case? Thanks again for helping this newbie out. Best, Laird [Message sent by forum member 'ljnelson' (ljnelson)] http://forums.java.net/jive/thread.jspa?messageID=295232 === 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".
Re: [JAVA2D] Copying a portion of an Image?
> // 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 OK; thanks. > If you didn't want a snapshot, I can outline other > ways, but I'm > guessing that this is probably what you wanted...? Yep. What allowed you to know that TYPE_INT_RGB was the correct parameter to pass in the BufferedImage constructor? If it helps, I know that the source image often has an alpha value set. Would I use TYPE_INT_RGBA in this case? Thanks again for helping this newbie out. Best, Laird [Message sent by forum member 'ljnelson' (ljnelson)] http://forums.java.net/jive/thread.jspa?messageID=295232 === 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".
Re: [JAVA2D] Copying a portion of an Image?
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".
Re: [JAVA2D] Copying a portion of an Image?
I'd suggest starting with a BufferedImage rather than an Image. They don't play well together... [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".
[JAVA2D] Copying a portion of an Image?
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".