//------------------------------------------------------------------------- /// <summary> /// Iterates through the pixels of the bitmap image. For each pixel, the /// specified <code>delegate</code> is called. Pixels are enumerated from /// the top left corner of the image, line by line. The <see cref="PixelData"/> /// is updated at each step of the enumeration; that is, a new /// <see cref="PixelData"/> instance is not created at each step. Modifying /// the <see cref="PixelData"/> will modify the bitmap image when the /// <see cref="Dispose"/> or <see cref="Flush"/> is invoked on the bitmap /// handler. /// </summary> /// <param name="enumerator">The <code>delegate</code> that will handle /// pixel enumeration.</param> public void Enumerate(EnumerationHandler enumerator) { if (!Locked) { throw new InvalidOperationException("The bitmap is no longer locked; pixel information is no longer maintained."); } PixelData pixel = new PixelData(); for (int ycoordinate = 0; ycoordinate < Bitmap.Height; ++ycoordinate) { int offset = ycoordinate * this.bitmapData.Stride; for (int xcoordinate = 0; xcoordinate < Bitmap.Width; ++xcoordinate) { int bIndex = offset + xcoordinate * BYTES_PER_PIXEL; int gIndex = bIndex + 1; int rIndex = gIndex + 1; pixel.X = xcoordinate; pixel.Y = ycoordinate; pixel.R = this.pixelData[rIndex]; pixel.G = this.pixelData[gIndex]; pixel.B = this.pixelData[bIndex]; enumerator(pixel); this.pixelData[rIndex] = pixel.R; this.pixelData[gIndex] = pixel.G; this.pixelData[bIndex] = pixel.B; } } }