/// <summary> /// Returns whether these two fast bitmaps match in width, height and pixel data within the given sub rectangle. /// </summary> /// <param name="fast_bitmap1"></param> /// <param name="fast_bitmap2"></param> /// <param name="sub_rect"></param> /// <returns></returns> public static bool IsMatch(FastBitmap fast_bitmap1, FastBitmap fast_bitmap2, Rectangle sub_rect) { if (fast_bitmap1.Width != fast_bitmap2.Width || fast_bitmap1.Height != fast_bitmap2.Height) { return(false); } int end_y = sub_rect.Y + sub_rect.Height; int end_x = sub_rect.X + sub_rect.Width; for (int y = sub_rect.Y; y < end_y; y++) { for (int x = sub_rect.X; x < end_x; x++) { if (fast_bitmap1.GetPixel(x, y) != fast_bitmap2.GetPixel(x, y)) { return(false); } } } return(true); }
public static bool IsMatch(FastBitmap fast_bitmap1, FastBitmap fast_bitmap2, int total_tolerance) { if (fast_bitmap1.Width != fast_bitmap2.Width || fast_bitmap1.Height != fast_bitmap2.Height) { return(false); } int total = 0; for (int y = 0; y < fast_bitmap1.Height; y++) { for (int x = 0; x < fast_bitmap1.Width; x++) { total += BitmapAnalyzer.AbsoluteDiff(fast_bitmap1.GetColor(x, y), fast_bitmap2.GetColor(x, y)); if (total > total_tolerance) { return(false); } } } return(true); }
public BitmapMask(Bitmap mask, int x, int y) { this.mask = new FastBitmap(mask); this.location = new Point(x, y); }
public bool IsIn(FastBitmap bitmap, int tolerance) { return(this.mask.IsIn(bitmap, this.location, tolerance)); }
public BitmapMask(FastBitmap mask, int x, int y) { this.mask = mask; this.location = new Point(x, y); }
public BitmapMask(Bitmap mask, Point location) { this.mask = new FastBitmap(mask); this.location = location; }
public BitmapMask(FastBitmap mask, Point location) { this.mask = mask; this.location = location; }
public static int AbsoluteDiff(FastBitmap bmp1, FastBitmap bmp2) { return(AbsoluteDiff(bmp1, bmp2, new Rectangle(0, 0, bmp1.Width, bmp1.Height))); }
public static Rectangle BoundingRectangle(Bitmap bmp, Rectangle bounds, int bound_color) { FastBitmap fbmp = new FastBitmap(bmp); int s_x = 0, e_x = 0, s_y = 0, e_y = 0; bool done = false; for (int x = bounds.X; x < bounds.X + bounds.Width && !done; x++) { for (int y = bounds.Y; y < bounds.Y + bounds.Height; y++) { if (fbmp.GetPixel(x, y) == bound_color) { s_x = x; done = true; break; } } } done = false; for (int x = bounds.X + bounds.Width - 1; x >= bounds.X && !done; x--) { for (int y = bounds.Y; y < bounds.Y + bounds.Height; y++) { if (fbmp.GetPixel(x, y) == bound_color) { e_x = x; done = true; break; } } } done = false; for (int y = bounds.Y; y < bounds.Y + bounds.Height && !done; y++) { for (int x = bounds.X; x < bounds.X + bounds.Width; x++) { if (fbmp.GetPixel(x, y) == bound_color) { s_y = y; done = true; break; } } } done = false; for (int y = bounds.Y + bounds.Height - 1; y >= bounds.Y && !done; y--) { for (int x = bounds.X; x < bounds.X + bounds.Width; x++) { if (fbmp.GetPixel(x, y) == bound_color) { e_y = y; done = true; break; } } } fbmp.UnlockBitmap(); //Console.WriteLine(s_x + " " + e_x + " " + s_y + " " + e_y); Rectangle crop_rect = new Rectangle(s_x, s_y, e_x - s_x + 1, e_y - s_y + 1); return(crop_rect); }
/// <summary> /// Saves to file but does not overwrite filename if it already exists, it insted adds a new number to the end. /// </summary> /// <param name="bitmap"></param> /// <param name="filepath"></param> public static void SaveToFile(FastBitmap bitmap, string filepath) { bitmap.Bitmap.Save(PathHelper.GenerateNextFilePath(filepath)); }
public bool IsMatch(FastBitmap bitmap) { return(bitmap.GetPixel(X, Y) == color); }