这是程序, SendKeys.SendWait("{Prtsc}"); Bitmap imgBitMap = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);F5 Debug的时候会提示这个“Object reference not set to an instance of an object.”剪切板里是空的
//获取当前屏幕的大小 Rectangle screenRectangle = Screen.PrimaryScreen.Bounds; //创建图片 m_copyImage = new Bitmap(screenRectangle.Width, screenRectangle.Height); //创建句柄,拷贝屏幕图片 Graphics g = Graphics.FromImage(m_copyImage); g.CopyFromScreen(new Point(0, 0), new Point(0, 0),screenRectangle.Size,CopyPixelOperation.SourceCopy); //设置当前窗口的大小 Width = m_copyImage.Width; Height = m_copyImage.Height; Left = 0; Top = 0; //设置图片 drawArea1.BackgroundImage = m_copyImage; //m_copyImage.Save("c:\\2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); g.Save(); //释放资源 g.Dispose();
SendKeys.SendWait("{Prtsc}");
Bitmap imgBitMap = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);F5 Debug的时候会提示这个“Object reference not set to an instance of an object.”剪切板里是空的
Rectangle screenRectangle = Screen.PrimaryScreen.Bounds; //创建图片
m_copyImage = new Bitmap(screenRectangle.Width, screenRectangle.Height); //创建句柄,拷贝屏幕图片
Graphics g = Graphics.FromImage(m_copyImage);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0),screenRectangle.Size,CopyPixelOperation.SourceCopy); //设置当前窗口的大小
Width = m_copyImage.Width;
Height = m_copyImage.Height;
Left = 0;
Top = 0; //设置图片
drawArea1.BackgroundImage = m_copyImage; //m_copyImage.Save("c:\\2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); g.Save(); //释放资源
g.Dispose();