C# 화면 캡쳐 Capture
1. 비트맵으로
byte[] byteArray;
public void Capture()
{
System.Drawing.Rectangle rect = Screen.PrimaryScreen.Bounds;
Bitmap tBitmap = new Bitmap(rect.Width, rect.Height);
using (Graphics tGraphics = Graphics.FromImage(tBitmap))
{
tGraphics.CopyFromScreen(rect.Left, rect.Top, 0, 0, rect.Size);
}
byteArray = ImageToByte(tBitmap);
}
public static byte[] ImageToByte(System.Drawing.Image img)
{
ImageConverter converter = new ImageConverter();
return (byte[])converter.ConvertTo(img, typeof(byte[]));
}
2. 이미지로
private void ScreenShotToImage()
{
var screenSize = new System.Drawing.Size((int)SystemParameters.VirtualScreenWidth, (int)SystemParameters.VirtualScreenHeight);
try
{
using (var img = ScreenShot.CaptureImage(System.Drawing.Point.Empty, System.Drawing.Point.Empty, screenSize))
{
UpdateImage(img);
}
addListItem("Sending to Capture Image for Server");
}
catch (Exception ex)
{
App.WriteLine(ex.Message);
}
}
public class ScreenShot
{
public static Image CaptureImage(Point SourcePoint, Point DestinationPoint, Size size, int reduceScale = 4)
{
using (Bitmap bitmap = new Bitmap(size.Width, size.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(SourcePoint, DestinationPoint, size);
}
return bitmap.GetThumbnailImage(size.Width / reduceScale, size.Height / reduceScale, null, IntPtr.Zero);
}
}
}
'C# > Image | Video' 카테고리의 다른 글
C# Byte To ImageSource (0) | 2020.07.30 |
---|---|
이미지 EXIF 정보 가져오기, 이미지 회전 후 저장 (0) | 2020.07.27 |
C# Image To Byte (0) | 2020.07.27 |
C# lock 없이 비트맵 이미지 픽셀 Get/Set (0) | 2020.07.27 |