将动画 .gif 文件转换为 .bmp 条 [英] Converting animated .gif file into a .bmp strip
问题描述
我想知道是否有人可以指导我或指导我使用 .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*宽度开始.
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屋!