Results 1 to 11 of 11
Thread: copyArea from 1 image to another
- 04-29-2010, 08:45 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 88
- Rep Power
- 0
copyArea from 1 image to another
Okay so. Lets say we have image1, now we want image2 to equal a specified area of image1.
I know the graphics class has a method called copyArea which I thought was going to be very useful, but it turned out that it only copies an area and translates it to another position on the same pane that the Graphics class was painting on.
so how do I get the copied area onto the new image?
Also, when i get that i'm going to want it to stretch to the width of the applet, how do you stretch an image?
- 04-29-2010, 09:25 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,147
- Rep Power
- 5
Create a BufferedImage, then you can use its Graphics object to draw from the original image.
Background Panel shows how you can scale an image.Last edited by camickr; 04-30-2010 at 02:59 AM.
- 04-30-2010, 01:44 AM #3
Member
- Join Date
- Mar 2010
- Posts
- 88
- Rep Power
- 0
How do you use Graphics objects to draw from the original image? lol... that was my question, how can i draw to image 2 using image 1's graphics, and you said use Graphics object to draw from the original image....
-
Create a BufferedImage using one of its constructors. You'll need to get the size of the original image for two of the parameters and decide on a BufferedImage graphics type. Then get the Graphics object from the BufferedImage via its getGraphics() method. You should then be able to draw an image on this with the Graphics#drawImage(....) method. Experiment. Search the forum for examples. Have fun!
edit: I see that you want to draw a specified area of the original image. So your BufferedImage width and height will be the width and height of this specified area. I believe that drawImage will have an overload that will allow you to specify a region of the original image.Last edited by Fubarable; 04-30-2010 at 02:03 AM.
- 04-30-2010, 02:10 AM #5
Member
- Join Date
- Mar 2010
- Posts
- 88
- Rep Power
- 0
What do you mean a BufferedImage graphics type?
when i look through the API i end up getting into a bunch of differant classes.
Is there no simple way to take what's been custom painted to a JLabel(have it all in an image as well as it paints to the image before painting the image to the label), take an area of it(100*100 rectangle around where mouse is clicked), save that into an image, and scale that to the width and height of the JLabel and paint it on top of it? Like zooming in kind of thing.
-
Please look up the BufferedImage API to see the public static final fields available for use as an int parameter for its constructor. Then experiment and see what happens. You can't break your computer! :)
I'm not pro at this, but what we're recommending here isn't that hard. Again, play with it. Again, search the forum as there are plenty of examples of use of BufferedImages.Is there no simple way to take what's been custom painted to a JLabel(have it all in an image as well as it paints to the image before painting the image to the label), take an area of it(100*100 rectangle around where mouse is clicked), save that into an image, and scale that to the width and height of the JLabel and paint it on top of it? Like zooming in kind of thing.
Luck!
- 04-30-2010, 02:55 AM #7
Member
- Join Date
- Mar 2010
- Posts
- 88
- Rep Power
- 0
I got it.
Thanks for pointing me towards BufferedImage, wasn't aware of it's existance.
By the way, just a side note, is there any specific reason to use Graphics2D over Graphics?
- 04-30-2010, 03:00 AM #8
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,147
- Rep Power
- 5
Really? What did the first reply suggest?Thanks for pointing me towards BufferedImage, wasn't aware of it's existance.
- 04-30-2010, 03:01 AM #9
Member
- Join Date
- Mar 2010
- Posts
- 88
- Rep Power
- 0
- 04-30-2010, 03:02 AM #10
Member
- Join Date
- Mar 2010
- Posts
- 88
- Rep Power
- 0
And i also couldn't just take the graphics from the image, i just said bufferedImage = bufferedImage.getSubimage(x, y, w ,h);
Regards...
- 04-30-2010, 03:08 AM #11
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,147
- Rep Power
- 5
And when you read the API, what class did you find? Is it such a leap to think a typo was made? Or better yet why did you not question it?BufferImage, i thought you were refering to using an image as an offscreen buffer
I didn't suggest that.And i also couldn't just take the graphics from the image,
No idea what you are suggesting a BufferedImage is created empty, so there is no sub image to get, that is why I suggested you need to draw the original image onto it.i just said bufferedImage = bufferedImage.getSubimage(x, y, w ,h);
Similar Threads
-
Problems drawing a section of an image onto another image.
By Cain in forum Java 2DReplies: 1Last Post: 04-17-2009, 12:44 AM -
[SOLVED] manipulating the pixel values of an image and constructinf a new image from
By sruthi_2009 in forum AWT / SwingReplies: 14Last Post: 04-10-2009, 08:46 AM -
Canvas Image popups another image (SWT)
By SpaceY in forum New To JavaReplies: 2Last Post: 11-11-2008, 01:25 PM -
drawing an image to an offscreen image
By hunterbdb in forum Java 2DReplies: 9Last Post: 10-30-2008, 06:17 PM -
Converting multiple banded image into single banded image... Image enhancement
By archanajathan in forum Advanced JavaReplies: 0Last Post: 01-08-2008, 05:29 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks