public Bitmap CaptureScreen(int x, int y, Size size, bool useGDI) { if (_testScreenshot != null) { return(BitmapProcessor.Copy(_testScreenshot, new Rectangle(new Point(x, y), size))); } else if (useGDI) { IntPtr hDesk = GetDesktopWindow(); IntPtr hSrce = GetWindowDC(hDesk); IntPtr hDest = CreateCompatibleDC(hSrce); IntPtr hBmp = CreateCompatibleBitmap(hSrce, size.Width, size.Height); IntPtr hOldBmp = SelectObject(hDest, hBmp); bool b = BitBlt(hDest, 0, 0, size.Width, size.Height, hSrce, x, y, CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt); Bitmap bmp = Bitmap.FromHbitmap(hBmp); SelectObject(hDest, hOldBmp); DeleteObject(hBmp); DeleteDC(hDest); ReleaseDC(hDesk, hSrce); return(bmp); } else { Bitmap memoryImage = new Bitmap(size.Width, size.Height); System.Drawing.Graphics memoryGraphics = System.Drawing.Graphics.FromImage(memoryImage); memoryGraphics.CopyFromScreen(x, y, 0, 0, size); return(memoryImage); } }
/// <summary>Видаляє білі вертикалі в кінці зображення</summary> /// <param name="bmp">Зображення для обробки</param> public static void TrimEnd(ref Bitmap bmp, int leave) { bool ok = true; int count = 0; while (count < bmp.Width - 1) { for (int y = 0; y < bmp.Height; y++) { Color c = bmp.GetPixel(bmp.Width - count - 1, y); if (!ColorsEqual(c, Color.White)) { ok = false; break; } } if (!ok) { break; } else { count++; } } BitmapProcessor.Copy(ref bmp, new Rectangle(0, 0, Math.Min(bmp.Width - count + leave, bmp.Width), bmp.Height)); }
public static bool Contains(Bitmap bmp, Bitmap subBmp, int colorDiff, int diff) { for (int x = 0; x <= bmp.Width - subBmp.Width; x++) { for (int y = 0; y <= bmp.Height - subBmp.Height; y++) { Bitmap temp = BitmapProcessor.Copy(bmp, new Rectangle(new Point(x, y), subBmp.Size)); if (AreEqual(temp, subBmp, colorDiff, diff)) { temp.Dispose(); return(true); } temp.Dispose(); } } return(false); }