public void PerPixelInArea(Rectangle area, PixelHandler pixelHandler) { if (area.X + area.Width > PixelWidth) { throw new ArgumentException($"Requested Rectangle {area} does not fit into the bounds of the bitmap width {PixelWidth}"); } if (area.Y + area.Height > PixelHeight) { throw new ArgumentException($"Requested Rectangle {area} does not fit into the bounds of the bitmap height {PixelHeight}"); } var pixelExtractor = PixelColorExtractor.Create(PixelFormat); int pixelWidth = area.X; int pixelHeight = area.Y; int pixelFinalWidth = (area.X + area.Width); int byteIndex = PixelXYToByteIndex(area.X, area.Y); int byteFinalIndex = PixelXYToByteIndex(0, area.Y + area.Height); int A = 255; int R = 255; int G = 255; int B = 255; while (byteIndex < byteFinalIndex) { pixelExtractor.ExtractPixelBytesToColor(RawPixelBytes, byteIndex, ref A, ref R, ref G, ref B); pixelHandler?.Invoke(pixelWidth - area.X, pixelHeight - area.Y, A, R, G, B); pixelWidth++; if (pixelWidth >= pixelFinalWidth) { pixelWidth = area.X; pixelHeight++; } byteIndex = PixelXYToByteIndex(pixelWidth, pixelHeight); A = 255; R = 255; G = 255; B = 255; } }
public static void RegisterPixelColorExtractor(PixelColorExtractor extractor) { RegisteredColorExtractors.Remove(extractor.PixelFormat); RegisteredColorExtractors.Add(extractor.PixelFormat, extractor); }