如何分割GIF动画在.net中? [英] How to split an animated gif in .net?
问题描述
如何在.NET拆分GIF动画成为其组成部分?
我特别想要将其加载到图像(S)(System.Drawing.Image对象)在内存中。
======================
根据SLaks的回答,我现在这个
公共静态的IEnumerable<位图> GetImages(流流)
{
使用(VAR gifImage = Image.FromStream(流))
{
变种尺寸=新FrameDimension(gifImage.FrameDimensionsList [0]); //获取GUID
VAR frameCount = gifImage.GetFrameCount(尺寸); //在动画总帧数
对于(VAR指数= 0;指数< frameCount;指数++)
{
gifImage.SelectActiveFrame(尺寸,索引); //寻找帧
收益回报(位图)gifImage.Clone(); //返回它的一个副本
}
}
}
使用的 SetActiveFrame
方法来选择图像的活动帧
实例拿着动画GIF。例如:
image.SelectActiveFrame(FrameDimension.Time,FRAMEINDEX);
要得到的帧数,呼叫 GetFrameCount(FrameDimension.Time)
如果你只是想播放动画,你可以把它变成一个图片或使用的 ImageAnimator
类。
How do you split an animated gif into its component parts in .net?
Specifically i want to load them into Image(s) (System.Drawing.Image) in memory.
======================
Based on SLaks' answer i now have this
public static IEnumerable<Bitmap> GetImages(Stream stream)
{
using (var gifImage = Image.FromStream(stream))
{
var dimension = new FrameDimension(gifImage.FrameDimensionsList[0]); //gets the GUID
var frameCount = gifImage.GetFrameCount(dimension); //total frames in the animation
for (var index = 0; index < frameCount; index++)
{
gifImage.SelectActiveFrame(dimension, index); //find the frame
yield return (Bitmap) gifImage.Clone(); //return a copy of it
}
}
}
Use the SetActiveFrame
method to select the active frame of an Image
instance holding an animated GIF. For example:
image.SelectActiveFrame(FrameDimension.Time, frameIndex);
To get the number of frames, call GetFrameCount(FrameDimension.Time)
If you just want to play the animation, you can put it into a PictureBox or use the ImageAnimator
class.
这篇关于如何分割GIF动画在.net中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!