相关疑难解决方法(0)

C#gif图像到MemoryStream并返回(丢失动画)

我有一个小问题,我找不到任何解决方案.我想将GIF转换为byte []然后再转换为GIF.我工作正常,但我失去了动画.

当我开始时它是一个完美的动画GIF(我在一个PictureBox元素中显示它).但是转换后我遇到了第一帧.

HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create("creativetechs.com/i/tip_images/ExampleAnimation.gif");
HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream stream = httpWebReponse.GetResponseStream();
Image img = Image.FromStream(stream);

MemoryStream ms = new MemoryStream();
img.Save(ms,img.RawFormat);
byte [] bytes = ms.ToArray();
Image img2 = Image.FromStream(new MemoryStream(bytes));

int frames1 = img.GetFrameCount(System.Drawing.Imaging.FrameDimension.Time);
int frames2 = img2.GetFrameCount(System.Drawing.Imaging.FrameDimension.Time);
Run Code Online (Sandbox Code Playgroud)

我也尝试过不使用RawFormat System.Drawing.Imaging.ImageFormat.Gif.没改变一件事.frames1是正确的帧数.frames2是1.

PictureBox我的GUI中有2个元素.一个展示img和另一个img2.但是img2不是动画img.怎么了?

我也尝试使用序列化来创建我的byte [].

我将图像序列化并再次反序列化,它也没有改变任何东西.这怎么可能?

c# animation gif stream

13
推荐指数
1
解决办法
8883
查看次数

标签 统计

animation ×1

c# ×1

gif ×1

stream ×1