WinForm截屏

 public void CutAppForm(int Localtion_X,int Localtion_Y, int picWidth,int picHeight,ref byte[] bytes)
 {
     string filePath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
     string fileName = DateTime.Now.ToString("yyyy?MM?dd?HH?mm?ss?") + ".jpg";
     try
     {
         Screen screen = Screen.AllScreens.FirstOrDefault();
         Rectangle rc = new Rectangle(Localtion_X, Localtion_Y, picWidth, picHeight);

         Bitmap bitmap = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);
         this.DrawToBitmap(bitmap, rc);

         using (Graphics memoryGrahics = Graphics.FromImage(bitmap))
         {
             memoryGrahics.CopyFromScreen(rc.X, rc.Y, 0, 0, rc.Size, CopyPixelOperation.SourceCopy);//?????????????
         }
         bitmap.Save(filePath + fileName, ImageFormat.Png);
         MessageBox.Show("?????:" + filePath + fileName);

         MemoryStream ms = new MemoryStream();
         bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
         ms.Seek(0, System.IO.SeekOrigin.Begin);
         bytes = new byte[ms.Length];
         ms.Read(bytes, 0, bytes.Length);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }

 [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
 public static extern bool BitBlt(IntPtr hdcDest, 
                                      int nXDest,
                                      int nYDest,
                                      int nWidth,
                                      int nHeight,
                                      IntPtr hdcSrc,  
                                      int nXSrc,
                                      int nYSrc,
                                      System.Int32 dwRop  
                                      );
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章