using System.Drawing;
using System.IO;
using System.Drawing.Imaging;

namespace Icarus.Graphics.Animation
{
    public class SimpleFramesetProvider 
		: IFramesetProvider
	{
		public void fillFrameset(Frameset frameSet, Bitmap source) 
		{
			//Get frame count:
			FrameDimension fd = new FrameDimension(source.FrameDimensionsList[0]);
			int frameCount = source.GetFrameCount(FrameDimension.Time);

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

				source.SelectActiveFrame(fd, i);
				source.Save(stream, ImageFormat.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)
		{
			throw new System.NotImplementedException("Sorry, but at this point, .NET cannot generate animated GIFs. Please try one of the other Frameset Providers.");
		}
	}
}
