将动画的.gif文件转换为.bmp条 [英] Converting animated .gif file into a .bmp strip

查看:108
本文介绍了将动画的.gif文件转换为.bmp条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以指导我或指导我以便使用.gif图像并将其转换为.bmp条形图像文件.

I was wondering if someone can direct me or guide me in order to use a .gif image and convert it into a .bmp strip image file.

推荐答案

首先,您需要获取gif的大小.然后,您需要找出有多少帧.

First, you need to get the gif's size. Then you need to find out how many frames there are.

此后,您需要创建一个新图像,其高度=原始高度,宽度=框架* Gif宽度.

After that you need to create a new image with Height = original height, and Width = Frames * Gif Width.

然后,您必须将原始Gif的帧粘贴到该条中,如下所示:N帧从像素N * Width开始.

Then you must paste the original Gif's frames into the strip like so: Frame N starts at pixel N*Width.

那是如果您要制作水平条.

That is if you're making a horizontal strip.

这是控制台应用程序的完整代码:

And here is the complete code for a console application:

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

foreach (var arg in args)
    {
        Image gif = Image.FromFile(arg);
        FrameDimension dim = new FrameDimension(gif.FrameDimensionsList[0]);
        int frames = gif.GetFrameCount(dim);

        Bitmap resultingImage = new Bitmap(gif.Width * frames, gif.Height);

        for (int i = 0; i < frames; i++)
        {
            gif.SelectActiveFrame(dim, i);

            Rectangle destRegion = new Rectangle(gif.Width * i, 0, gif.Width, gif.Height);
            Rectangle srcRegion = new Rectangle(0, 0, gif.Width, gif.Height);

            using (Graphics grD = Graphics.FromImage(resultingImage))
            {
                grD.DrawImage(gif, destRegion, srcRegion, GraphicsUnit.Pixel);
            }
        }

        resultingImage.Save("res.png", ImageFormat.Png);
    }

生成的图像以名称res.png保存在已编译的控制台应用程序二进制文件目录中.您可以让该应用将生成的图像保存在源文件所在的位置,询问是否制作水平或垂直条带,等等.

The resulting image is saved in the compiled console app binary file directory under the name res.png. You can make the app save the resulting image right where the source file is, ask whether to make a horizontal or vertical strip, etc.

这篇关于将动画的.gif文件转换为.bmp条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆