Bạn có thể muốn sử dụng cái gì đó như Camtasia. Phụ thuộc vào lý do bạn tạo video.
Tôi sử dụng phiên bản viết lại của Jeff's User-Friendly Exception Handling và anh ấy sử dụng BitBlt từ GDI để chụp ảnh màn hình. Có vẻ đủ nhanh với tôi, nhưng tôi đã không đánh giá nó, và chúng tôi chỉ sử dụng nó cho một bức ảnh tại một thời điểm khi có một ngoại lệ unhandled ném.
#region Win32 API screenshot calls
// Win32 API calls necessary to support screen capture
[DllImport("gdi32", EntryPoint = "BitBlt", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int BitBlt(int hDestDC, int x, int y, int nWidth, int nHeight, int hSrcDC, int xSrc,
int ySrc, int dwRop);
[DllImport("user32", EntryPoint = "GetDC", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int GetDC(int hwnd);
[DllImport("user32", EntryPoint = "ReleaseDC", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int ReleaseDC(int hwnd, int hdc);
#endregion
private static ImageFormat screenshotImageFormat = ImageFormat.Png;
/// <summary>
/// Takes a screenshot of the desktop and saves to filename and format specified
/// </summary>
/// <param name="fileName"></param>
private static void TakeScreenshotPrivate(string fileName)
{
Rectangle r = Screen.PrimaryScreen.Bounds;
using (Bitmap bitmap = new Bitmap(r.Right, r.Bottom))
{
const int SRCCOPY = 13369376;
using (Graphics g = Graphics.FromImage(bitmap))
{
// Get a device context to the windows desktop and our destination bitmaps
int hdcSrc = GetDC(0);
IntPtr hdcDest = g.GetHdc();
// Copy what is on the desktop to the bitmap
BitBlt(hdcDest.ToInt32(), 0, 0, r.Right, r.Bottom, hdcSrc, 0, 0, SRCCOPY);
// Release device contexts
g.ReleaseHdc(hdcDest);
ReleaseDC(0, hdcSrc);
string formatExtension = screenshotImageFormat.ToString().ToLower();
string expectedExtension = string.Format(".{0}", formatExtension);
if (Path.GetExtension(fileName) != expectedExtension)
{
fileName += expectedExtension;
}
switch (formatExtension)
{
case "jpeg":
BitmapToJPEG(bitmap, fileName, 80);
break;
default:
bitmap.Save(fileName, screenshotImageFormat);
break;
}
// Save the complete path/filename of the screenshot for possible later use
ScreenshotFullPath = fileName;
}
}
}
/// <summary>
/// Save bitmap object to JPEG of specified quality level
/// </summary>
/// <param name="bitmap"></param>
/// <param name="fileName"></param>
/// <param name="compression"></param>
private static void BitmapToJPEG(Image bitmap, string fileName, long compression)
{
EncoderParameters encoderParameters = new EncoderParameters(1);
ImageCodecInfo codecInfo = GetEncoderInfo("image/jpeg");
encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, compression);
bitmap.Save(fileName, codecInfo, encoderParameters);
}
Từ "fotogram" có phải là từ thực tế không? – bzlm
Có rất nhiều ứng dụng thực hiện điều này thật đẹp mắt. Bạn có chắc chắn muốn phát minh lại bánh xe không? –
Hãy xem ... đây có phải là trang web "ứng dụng hữu ích" hay trang web câu hỏi lập trình không? Đó là một trong số họ, nhưng tôi vẫn quên điều đó. – bzlm