File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to display/draw part of a gif file. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to display/draw part of a gif file." Watch "How to display/draw part of a gif file." New topic
Author

How to display/draw part of a gif file.

Scott Matthews
Ranch Hand

Joined: Jun 28, 2001
Posts: 36
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
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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!


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Scott Matthews
Ranch Hand

Joined: Jun 28, 2001
Posts: 36
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).]
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Whoops! Sorry! Those should have been in there... guess I didn't copy/paste enough of the line from my code...
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
That's pretty slick, Nate.
Reuben Cleetus
Ranch Hand

Joined: Jul 13, 2001
Posts: 50
Nathan, you've provided me with my first good laugh of the morning!! And to think it came from a programming site! =)
Keep it up!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to display/draw part of a gif file.