(轉)C#實現錄屏功能


  轉帖,C#實現錄屏功能

  參考了一些方法,實現了錄屏功能。(我的機器必須安裝WMEncoder_cn.exe。稍微改寫了下提供的代碼。另改寫成VB.NET后有異常,原因待查。。。)

  環境: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;

    //開始錄制
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Encoder = new WMEncoder();

                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 == "屏幕視頻/音頻 - 高(CBR)")
                    {
                        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;

                if (label1.Text != string.Empty)
                {
                    File.LocalFileName = @"C:\1.WMA"; //保存路徑
                }
                else
                {
                    MessageBox.Show("請先選擇路徑!");
                    return;
                }

                Encoder.Start();
            }
            catch (Exception ex)
            {
                
            } 

        }

    //停止錄制

        private void button3_Click(object sender, EventArgs e)
        {
            Encoder.Stop();
        }

錄屏工程詳見:http://download.csdn.net/detail/yysyangyangyangshan/4056621,編程環境VS2008。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM