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。

你可能感兴趣的:(exception,windows,C#,File,null,audio)