C#实现录屏功能

参考了一些方法,实现了录屏功能。

环境:windows xp

用到的dll为:Interop.WMEncoderLib.dll,下载地址:http://download.csdn.net/detail/yysyangyangyangshan/4056611。如果有条件再安装上WMEncoder_cn.exe,下载地址:http://download.csdn.net/detail/yysyangyangyangshan/4056628。主要录屏方法如下:

WMEncoder Encoder = null;
            try
            {
                Encoder = WMEncoderManager.GetWMEncoder;

                IWMEncSourceGroup SrcGrp;

                IWMEncSourceGroupCollection SrcGrpColl;

                SrcGrpColl = Encoder.SourceGroupCollection;

                SrcGrp = SrcGrpColl.Add("SG_1");

                IWMEncSource SrcVid = null;

                IWMEncSource SrcAud = null;

                SrcVid = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);

                SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);

                SrcAud.SetInput("Default_Audio_Device", "Device", "");

                SrcVid.SetInput("ScreenCapture1", "ScreenCap", "");

                IWMEncProfileCollection ProColl;

                IWMEncProfile Pro;

                int i;

                long lLength;

                ProColl = Encoder.ProfileCollection;

                lLength = ProColl.Count;

                for (i = 0; i < lLength - 1; i++)
                {
                    Pro = ProColl.Item(i);

                    if (Pro.Name == WMEncoderManager.DefaultFormat)
                    {
                        SrcGrp.set_Profile(Pro);

                        break;
                    }
                }
                IWMEncDisplayInfo Descr;

                Descr = Encoder.DisplayInfo;

                Descr.Author = "";

                Descr.Copyright = "";

                Descr.Description = "";

                Descr.Rating = "";

                Descr.Title = "";

                IWMEncAttributes Attr;

                Attr = Encoder.Attributes;

                IWMEncFile File;

                File = Encoder.File;

                File.LocalFileName = "保存路径";

                Encoder.Start();
            }
            catch (Exception e)
            {
                Debug.Assert(false, e.Message);
            }

录屏工程详见:http://download.csdn.net/detail/yysyangyangyangshan/4056621,编程环境VS2008。

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值