【问题标题】:Why assigning an Image object containing gif to a new instance of Bitmap, breaks the gif为什么将包含 gif 的 Image 对象分配给 Bitmap 的新实例会破坏 gif
【发布时间】:2016-04-13 07:53:14
【问题描述】:

Image 对象包含一个 gif 文件,如果将其保存到磁盘并打开,则该 gif 可以正确显示。但是,如果从图像实例创建 Bitmap 对象并保存,则 gif 将不再有效:

 WebClient client = new WebClient();
 client.DownloadFile(new Uri("http://www.ajaxload.info/images/exemples/25.gif"), "25.gif");

 Image original = Image.FromFile("25.gif");
 original.Save("25-WorksFine.gif", ImageFormat.Gif);

 Bitmap bmp = new Bitmap(original);
 bmp.Save("25-Broken.gif", ImageFormat.Gif);

【问题讨论】:

    标签: c# .net winforms bitmap gif


    【解决方案1】:

    Bitmap 不支持动画文件。

    【讨论】:

    【解决方案2】:

    Image.FromFile 使用本机 GDI+ 通过适当的解码器加载文件

    new Bitmap(Image) 创建一个图像大小的绘图表面(Graphics),然后使用 Graphics.DrawImage 在其上绘制图像

    我想在最后一种情况下没有动画被保留

    【讨论】:

      猜你喜欢
      • 2019-10-27
      • 2021-08-03
      • 2010-10-31
      • 2013-03-23
      • 2021-04-22
      • 2020-12-18
      • 2013-03-21
      • 1970-01-01
      • 2020-07-29
      相关资源
      最近更新 更多