再 nuget 中 搜索 shapAvi 并添加引用
github 地址:https://github.com/baSSiLL/SharpAvi
using SharpAvi; using SharpAvi.Codecs; using SharpAvi.Output; using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; namespace BankAutoTransfer.Common { public class Recorder { private readonly int zoomWidth; private readonly int zoomHeight; private readonly AviWriter writer; private readonly IAviVideoStream videoStream; private readonly Thread screenThread; /// <summary> /// 上一次图片 /// </summary> Bitmap lastBitmap = new Bitmap(10, 10); bool stop = false; /// <summary> /// 缩放 /// </summary> float zoom = 1; /// <summary> /// 鼠标是否点击 /// </summary> bool mouseclick = false; /// <summary> /// 钩子句柄 /// </summary> int hook = 0; /// <summary> /// 录制屏幕 /// </summary> /// <param name="fileName">要保存的文件名</param> /// <param name="codec">编码</param> /// <param name="quality">录制质量</param> /// <param name="zoom">缩放</param> public Recorder(string fileName, FourCC codec, int quality = 70, float zoom = 1.0F) { //设置缩放 宽高 zoomHeight = (int)Math.Floor(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height * zoom); zoomWidth = (int)Math.Floor(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width * zoom); this.zoom = zoom; //创建视频 writer = new AviWriter(fileName) { FramesPerSecond = 10, EmitIndex1 = true, }; //创建视频流 videoStream = CreateVideoStream(codec, quality); videoStream.Name = "Screencast"; //