Mega Code Archive

 
Categories / Delphi / Graphic
 

Screencapture with animated gif support!

Title: Screencapture with animated gif support! Question: How to create a screenshot of the entire screen, a selection or a specific window to a bitmap, jpeg compressed or (animated) GIF file? Answer: In may last year i promised to create a component which could take screenshots and save them in a gif image, and here it FINALLY is. :) This component can be used in ANY kind of application, royalty free with only 1 demand: credits! ============================================================== Description: This component can create screenshots of the screen (or portions of the screen). You can set a region of what you want to "photograph" by calling the function = TtspScreenCapture.SetRegion(ARegion: TCaptureRegion) After setting the region you must specify a capture mode. there are 4 capturemodes: - cmStillBitmap - cmStillJPEG - cmStillGIF - cmMotionGIF Now you can take a still image by calling the function = TtspScreenCapture.GetStillImage: TCaptureResult; According to the chosen capture mode you can access the screenshot in the proper TGraphic object: = TCaptureResult = record VBitmap: TBitmap; VJPEG: TJPEGImage; VGIFImage: TGIFImage; end; With these objects you can save the images to wherever you want them. Motion gifs require a little different approach. First you must set the capture mode to cmMotionGIF. Accordingly you must set the interval in which a screenshot should be taken by setting the property = TtspScreenCapture.MotionGifInterval: integer This property is in milliseconds. (1 second = 1000 millisecond) Everything is now ready for capturing. To activate the capturing set the property = TtspScreenCapture.Active: boolean; to true. while capturing you can read the current GIFImage by calling the function = TtspScreenCapture.GetMotionGif: TGIFImage; To stop capturing set the Active property back to false. The final Gif image is again accesible by calling the function GetMotionGIF. ====================================================================== Benchmark: The component also contains a function benchmark. this is a very simple function which calculates how much frames can be captured in 10 seconds. the result value is in captured frames per second (rounded). ======================================================================= well, this wraps it up for now. Good luck with using this component in your application! Nevertheless i have 1 more thing to tell you: 1. DON'T forget to credit me in your application. You got this for free so it would be quite fair to do this simple thing. ======================================================================== Have fun, Christiaan ten Klooster webmaster@tsp2000.tmfweb.nl www.tsp2000.tmfweb.nl