public unsafe static Color GetColor(this BitmapData data, int x, int y) { bool alpha = data.HasAlpha(); byte *ptr = data.PtrAt(x, y); if (alpha) { return(Color.FromArgb(ptr[3], ptr[2], ptr[1], ptr[0])); } else { return(Color.FromArgb(ptr[2], ptr[1], ptr[0])); } }
public unsafe static bool MatchesColor(this BitmapData data, int x, int y, Color color) { bool alpha = data.HasAlpha(); byte *ptr = data.PtrAt(x, y); if (alpha) { return(color.R == ptr[2] && color.G == ptr[1] && color.B == ptr[0] && color.A == ptr[3]); } else { return(color.R == ptr[2] && color.G == ptr[1] && color.B == ptr[0] && color.A == 255); } }
public unsafe static void SetColor(this BitmapData data, int x, int y, Color color) { bool alpha = data.HasAlpha(); byte *ptr = data.PtrAt(x, y); if (alpha) { ptr[2] = color.R; ptr[1] = color.G; ptr[0] = color.B; ptr[3] = color.A; } else { ptr[2] = color.R; ptr[1] = color.G; ptr[0] = color.B; } }
private unsafe static byte *PtrAt(this BitmapData data, Point point) => data.PtrAt(point.X, point.Y);