摘要:[WinForm] GetPrimaryScreenByteArray Method
/// <summary>
/// 取得螢幕的畫面,傳回位元組。
/// </summary>
/// <param name="screen"></param>
/// <param name="imageFormat"></param>
/// <returns></returns>
byte[] GetScreenByteArray(Screen screen, ImageFormat imageFormat)
{
using (var ms = new MemoryStream())
{
var sizScreen = Screen.PrimaryScreen.Bounds.Size;
using (var bmp = new Bitmap(sizScreen.Width, sizScreen.Height))
{
using (var g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(Point.Empty, Point.Empty, screen.Bounds.Size);
}
bmp.Save(ms, imageFormat);
}
return ms.ToArray();
}
}