如何更改批量的gif文件解析?

时间:2014-05-12 02:28:22

标签: c# winforms

我从许多小gif创建了动画gif文件。 我知道动画gif分辨率是512x512 现在我想从相同的gif创建相同的动画gif,但在我创建动画gif之前,我想首先将每个gif文件的分辨率从512x512更改为1024x1024

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < myGifList.Count; i++)
            {

            }
        }

在comboBox1中我现在只有一个选择&#34; 1024x1024&#34;的字符串。在form1的构造函数中,我做了:

comboBox1.Items.Add("1024x1024");

在SelectedIndexChanged事件中,我遍历文件,例如myGifList中的第一个索引包含:

C:\Users\bout0_000\AppData\Local\mws\My Weather Station\radar_temp_directory\radar006363.Gif

第二个索引包含:

C:\Users\bout0_000\AppData\Local\mws\My Weather Station\radar_temp_directory\radar006363.Gif

现在我想将每个文件名从512x512更改为1024x1024。因此,如果文件radar006363.gif wis now 512x512将其更改为1024x1024并执行myGifList中的所有文件。

myGifList是List

我想为myGifList中的所有文件制作批量分辨率转换器,从512x512到1024x1024。

编辑:

这就是我现在尝试的:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < myGifList.Count; i++)
            {
                Image img = Image.FromFile(myGifList[i]);
                resizeImage(1024, 1024, myGifList[i]);
                img.Save(@"c:\temp\newimages\" + Path.GetFileName(myGifList[i]));
            }
            unfreez.MakeGIF(myGifList, previewFileName, 8, true);
        }

和resizeImage方法:

public Image resizeImage(int newWidth, int newHeight, string stPhotoPath)
        {
            Image imgPhoto = Image.FromFile(stPhotoPath);

            int sourceWidth = imgPhoto.Width;
            int sourceHeight = imgPhoto.Height;

            //Consider vertical pics
            if (sourceWidth < sourceHeight)
            {
                int buff = newWidth;

                newWidth = newHeight;
                newHeight = buff;
            }

            int sourceX = 0, sourceY = 0, destX = 0, destY = 0;
            float nPercent = 0, nPercentW = 0, nPercentH = 0;

            nPercentW = ((float)newWidth / (float)sourceWidth);
            nPercentH = ((float)newHeight / (float)sourceHeight);
            if (nPercentH < nPercentW)
            {
                nPercent = nPercentH;
                destX = System.Convert.ToInt16((newWidth -
                      (sourceWidth * nPercent)) / 2);
            }
            else
            {
                nPercent = nPercentW;
                destY = System.Convert.ToInt16((newHeight -
                      (sourceHeight * nPercent)) / 2);
            }

            int destWidth = (int)(sourceWidth * nPercent);
            int destHeight = (int)(sourceHeight * nPercent);


            Bitmap bmPhoto = new Bitmap(newWidth, newHeight,
                      PixelFormat.Format24bppRgb);

            bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
                     imgPhoto.VerticalResolution);

            Graphics grPhoto = Graphics.FromImage(bmPhoto);
            grPhoto.Clear(Color.Black);
            grPhoto.InterpolationMode =
                InterpolationMode.HighQualityBicubic;

            grPhoto.DrawImage(imgPhoto,
                new Rectangle(destX, destY, destWidth, destHeight),
                new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
                GraphicsUnit.Pixel);

            grPhoto.Dispose();
            return bmPhoto;
        }

但保存的文件仍为512x512

0 个答案:

没有答案