本文整理汇总了C#中IEncoder.Write方法的典型用法代码示例。如果您正苦于以下问题:C# IEncoder.Write方法的具体用法?C# IEncoder.Write怎么用?C# IEncoder.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEncoder
的用法示例。
在下文中一共展示了IEncoder.Write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteAnimatedGif
private void WriteAnimatedGif(Bitmap src, Stream output, IEncoder ios, ResizeSettings queryString)
{
//http://www.fileformat.info/format/gif/egff.htm
//http://www.fileformat.info/format/gif/spec/44ed77668592476fb7a682c714a68bac/view.htm
//Heavily modified and patched from comments on http://bloggingabout.net/blogs/rick/archive/2005/05/10/3830.aspx
MemoryStream memoryStream = null;
BinaryWriter writer = null;
//Variable declaration
try
{
writer = new BinaryWriter(output);
memoryStream = new MemoryStream(4096);
//Write the GIF 89a sig
writer.Write(new byte[] { (byte)'G', (byte)'I', (byte)'F', (byte)'8', (byte)'9', (byte)'a' });
//We parse this from the source image
int loops = GetLoops(src.PropertyItems);
int[] delays = GetDelays(src.PropertyItems);//20736 (delays) 20737 (loop);
int frames = src.GetFrameCount(FrameDimension.Time);
for (int frame = 0; frame < frames; frame++)
{
//Select the frame
src.SelectActiveFrame(FrameDimension.Time, frame);
// http://radio.weblogs.com/0122832/2005/10/20.html
//src.MakeTransparent(); This call makes some GIFs replicate the first image on all frames.. i.e. SelectActiveFrame doesn't work.
using (Bitmap b = c.CurrentImageBuilder.Build(src,queryString,false)){
//Useful to check if animation is occuring - sometimes the problem isn't the output file, but the input frames are
//all the same.
//for (var i = 0; i < b.Height; i++) b.SetPixel(frame * 10, i, Color.Green);
// b.Save(memoryStream, ImageFormat.Gif);
ios.Write(b, memoryStream); //Allows quantization and dithering
}
GifClass gif = new GifClass();
gif.LoadGifPicture(memoryStream);
if (frame == 0)
{
//Only one screen descriptor per file. Steal from the first image
writer.Write(gif.m_ScreenDescriptor.ToArray());
//How many times to loop the image (unless it is 1) IE and FF3 loop endlessley if loop=1
if (loops != 1)
writer.Write(GifCreator.CreateLoopBlock(loops));
}
//Restore frame delay
int delay = 0;
if (delays != null && delays.Length > frame) delay = delays[frame];
writer.Write(GifCreator.CreateGraphicControlExtensionBlock(delay)); //The delay/transparent color block
writer.Write(gif.m_ImageDescriptor.ToArray()); //The image desc
writer.Write(gif.m_ColorTable.ToArray()); //The palette
writer.Write(gif.m_ImageData.ToArray()); //Image data
memoryStream.SetLength(0); //Clear the mem stream, but leave it allocated for now
memoryStream.Seek(0, SeekOrigin.Begin); //Reset memory buffer
}
writer.Write((byte)0x3B); //End file
}
finally
{
if (memoryStream != null) memoryStream.Dispose();
//if (writer != null) writer.Close
}
}