我的意思是我有这个代码我在硬盘上使用计时器创建许多gif文件来捕获桌面窗口。我每1秒拍一次截图。 例如,60秒后,我在硬盘上只有60个gif文件。
然后我使用我自己的动画gif类来创建GIF动画。 当我正在播放GIF动画时,似乎缺少许多帧。
现在我每秒都会截取dekstop窗口的屏幕截图。 但我想我应该采取每秒钟25个截图或60? 我该怎么做 ?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using System.IO;
using unfreez_wrapper;
namespace CapturedDesktop
{
public partial class Form1 : Form
{
int screens;
string gifsdirectory;
UnFreezWrapper unfreez;
public Form1()
{
InitializeComponent();
unfreez = new UnFreezWrapper();
screens = 0;
gifsdirectory = @"C:\Temp\CapturedDesktop\";
}
private void CaptureScreenshot()
{
screens++;
screenshots(gifsdirectory + screens.ToString("D6") + ".gif");
}
public static void screenshots(string filename)
{
//Create a new bitmap.
using (var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width - 100,
Screen.PrimaryScreen.Bounds.Height - 100,
PixelFormat.Format32bppArgb))
{
// Create a graphics object from the bitmap.
using (var gfxScreenshot = Graphics.FromImage(bmpScreenshot))
{
// Take the screenshot from the upper left corner to the right bottom corner.
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
Screen.PrimaryScreen.Bounds.Y,
0,
0,
Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);
}
// Save the screenshot to the specified path that the user has chosen.
bmpScreenshot.Save(filename, ImageFormat.Gif);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
CaptureScreenshot();
}
private void AnimatedGifButton_Click(object sender, EventArgs e)
{
List<string> myGifList = new List<string>();
FileInfo[] fi;
DirectoryInfo dir1 = new DirectoryInfo(gifsdirectory);
fi = dir1.GetFiles("*.gif");
for (int i = 0; i < fi.Length; i++)
{
myGifList.Add(fi[i].FullName);
}
unfreez.MakeGIF(myGifList, gifsdirectory + "agif", 100, true);
}
}
}
当我创建它时,问题不是动画gif速度,但它不是很平滑,就像丢帧一样。