I am able to display a GIF file to a JFrame with code similar to the following: . . Toolkit currentTK = Toolkit.getDefaultToolkit(); Image theWholeImage = currentTK.getImage("Whole.gif"); g.drawImage(theWholeImage,0,0,this); Now, I would like to "grab" part of the GIF once it is loaded above and display the part "grabbed". For example: Go to the original "Whole.gif" and grab from location 100,200 to location 200,400 and display this piece of the GIF file. What is the way to do this? I may need to refer to over 50 pieces of the GIF file so I do not want to have individual GIF files. Thanks
PixelGrabber is the answer to all your problems my friend! It slices! It dices! Look at what it does to this innocent little image named "Washu.gif"!
BAM! Those pixels are pulled right out of the image and are placed safely into this convenient integer array. "An integer array?!?!", You may be asking yourself. "But, Nathan, I wanted an image not some array of smegging integers?!?" That's where you would be wrong my friend, because we're only halfway done!
SPLOOSH! The suprisingly useful MemoryImageSource takes your array of pixels in one end and with a turn of the crank... What's that! YES! That's a shiny new Image coming out of the other end!
How much are these wonderful devices, you may ask... Well, how much would you pay for the convenience of only getting the parts you want from an Image? $39.99? $19.99? Well, if you act now and take advantage of this limited time Internet offer, available only though JavaRanch, they can be yours for the amazingly low price of... FREE! Yes, FREE! Take advantage of this limited offer and we will send you both the PixelGrabber and the MemoryImageSource absolutely free. If you are not completely satisfied, we'll completely refund your money! How's that for an offer!
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Jun 28, 2001
You Da Man. Thanks for the solution. FYI: I am new to java so the following may be a function of my greeness, but I had to make 2 changes to get the code to compile and run. If you are interested, these are the changes: 1. PixelGrabber pg = new PixelGrabber( img, 100, 200, width, height, 0, width ); changed to have "pixels" as one of the parameters PixelGrabber pg = new PixelGrabber( img, 100, 200, width, height, pixels, 0, width ); 2. Image smallImage = new MemoryImageSource( width, height, pixels, 0, width); changed to have "createImage()" in the line: Image smallImage = createImage(new MemoryImageSource( width, height, pixels, 0, width ));
Once again. Thanks for the solution. [This message has been edited by Scott Matthews (edited August 11, 2001).]