package Icarus.Graphics.Animation;

import System.Drawing.*;
import System.Drawing.Imaging.*;
import System.IO.*;

/**
 * This frameset provider simply goes through the frames of an animated image and adds them to the frameset. Basically, this one is good for things like animated GIFs.
 * 
 * @author $Author: asskoala $
 * @version $Revision: 1.1 $ $Date: 2005/12/11 21:07:21 $
 */
public class SimpleFramesetProvider implements IFramesetProvider
{
	/**
	 * Goes through the image and extracts frames from it.
	 */
	public void fillFrameset(Frameset frameSet, Bitmap source) 
	{
		//Get frame count:
		FrameDimension fd = new FrameDimension(source.get_FrameDimensionsList()[0]);
		int frameCount = source.GetFrameCount(fd.get_Time());

		//Save the frames:
		for (int i = 0; i < frameCount; i++) 
		{
			MemoryStream stream = new MemoryStream();

			source.SelectActiveFrame(fd, i);
			source.Save(stream, ImageFormat.get_Bmp());

			frameSet.addFrame(((Bitmap) Bitmap.FromStream(stream)), new Point(0, 0));
		}
	}

	/**
	 * Exports the frame as an animated gif.
	 */
	public void exportFrameset(Frameset frameset, String filename) throws System.Exception
	{
		throw new System.NotImplementedException("Sorry, but at this point, .NET cannot generate animated GIFs. Please try one of the other Frameset Providers.");
	}
}
