c#-截屏
来源:互联网 发布:淘宝评论折叠在哪里 编辑:程序博客网 时间:2024/06/06 08:45
//获得当前屏幕的分辨率 Screen scr = Screen.PrimaryScreen; Rectangle rc = scr.Bounds; int iWidth = rc.Width; int iHeight = rc.Height; //创建一个和屏幕一样大的Bitmap Image myImage = new Bitmap(iWidth, iHeight); //从一个继承自Image类的对象中创建Graphics对象 Graphics g = Graphics.FromImage(myImage); //抓屏并拷贝到myimage里 g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(iWidth, iHeight)); //保存为文件 try { if (myImage != null) { //检查是否存在该文件夹 if (!Directory.Exists(@"C:\sss")) { // Create Directory.CreateDirectory(@"C:\sss"); // Delete //Directory.Delete(@"C:\sss", true); } myImage.Save(@"C:\sss\myBitmap.bmp"); } } catch (Exception) { MessageBox.Show("There was a problem saving the file." + "Check the file permissions."); }
0 0