C#使用 SharpAVI进行 屏幕录制

再 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";
            //
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值