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
);
}