首页 > 代码库 > c#截图

c#截图

 截图

            Size screen = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

            Bitmap memoryImage = new Bitmap(screen.Width, screen.Height);

            Graphics memoryGraphics = Graphics.FromImage(memoryImage);

            memoryGraphics.CopyFromScreen(0, 0, 0, 0, screen, CopyPixelOperation.MergePaint);
            txtCc.Text = "yyyyMMddHHmmss";
            string jpg = DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
            memoryImage.Save(Environment.CurrentDirectory.ToString() + @"\" + jpg, ImageFormat.Jpeg);

            UpdateXml("jpg", jpg);

打开文件夹及关闭文件夹

  //打开文件夹
            //System.Diagnostics.Process.Start("explorer.exe", lblSelete.Text + @"\");
            //Thread.Sleep(5000);         
            //截图
            //Thread.Sleep(5000);   
            //关闭所有文件夹
            //System.Diagnostics.Process[] myPs;
            //myPs = System.Diagnostics.Process.GetProcesses();
            //foreach (System.Diagnostics.Process p in myPs)
            //{
            //    if (p.ProcessName.ToLower() == "explorer".ToLower())
            //    {
            //        try
            //        {
            //            p.Kill();
            //        }
            //        catch (Exception ex)
            //        {
            //        }
            //    }
            //}

 

 

其他

//try
            //{
            //    label9.Text = label1.Text + "2";
            //    Bitmap image = new Bitmap(System.Windows.Forms.SystemInformation.VirtualScreen.Width, System.Windows.Forms.SystemInformation.VirtualScreen.Height);
            //    using (Graphics g = Graphics.FromImage(image))
            //    {
            //        label9.Text = label1.Text + "3";
            //        g.CopyFromScreen(0, 0, 0, 0, image.Size);
            //        g.Dispose();
            //        string hour = DateTime.Now.Minute.ToString();
            //        string second = DateTime.Now.Second.ToString();
            //        string jpgfile = Environment.CurrentDirectory.ToString() + @"\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
            //        image.Save(jpgfile);
            //        UpdateXml("jpg", jpgfile);
            //        label9.Text = label1.Text + "4";
            //    }
            //}
            //catch (Exception  ex )
            //{
            //    label9.Text = label1.Text + ex;

            //}
            ////截取屏幕内容     
            //Graphics gSrc = http://www.mamicode.com/this.CreateGraphics();    //创建窗体的Graphics对象 
            //HandleRef hDcSrc = http://www.mamicode.com/new HandleRef(null, gSrc.GetHdc());>//int width = System.Windows.Forms.SystemInformation.VirtualScreen.Width;    //获取宽度 
            //int height = System.Windows.Forms.SystemInformation.VirtualScreen.Height;    //获取高度 

            //const int SRCCOPY = 0xcc0020;    //复制图块的光栅操作码 

            //Bitmap bmSave = new Bitmap(width, height);    //用于保存图片的位图对象 
            //Graphics gSave = Graphics.FromImage(bmSave);    //创建该位图的Graphics对象 
            //HandleRef hDcSave = new HandleRef(null, gSave.GetHdc());    //得到句柄 

            //BitBlt(hDcSave, 0, 0, width, height, hDcSrc, 0, 0, SRCCOPY);

            //gSrc.ReleaseHdc();
            //gSave.ReleaseHdc();

            //gSrc.Dispose();
            //gSave.Dispose();
            //string jpgfile = Environment.CurrentDirectory.ToString() + @"\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
            //Save(bmSave, jpgfile);           
            //UpdateXml("jpg", jpgfile);

 

c#截图