ruarai

PixelMap

Bitmap Alternative

The issues associated with editing bitmaps in .NET are not new. The GetPixel and SetPixel methods found in GDI+'s library are simply lackluster, offering extremely poor performance and surprising missing features.

Many solutions to the performance issue go through the route of low level memory management ('lockbits'), an ugly solution that requires unsafe code to be written. Whilst this offers the speed desired, it also adds unnecessary complexity to your code.

PixelMap solves this issue by replacing the Bitmap class entirely, offering a sleeker and faster approach to image manipulation. When an image needs to be converted to or from GDI's Bitmap, the low level memory management is handled out of sight safely.

PixelMap also offers color management in the form of the Pixel class, which gives developers access to color mixing and HSL constructors.

PixelMap is available for download through NuGet or from source on GitHub.

//Quickly load a PixelMap through a Bitmap
PixelMap map = new PixelMap("Lenna.png");
for (int x = 0; x < map.Width; x++)
{
    for (int y = 0; y < map.Height; y++)
    {
        //Sample a pixel
        Pixel pixel = map[x, y];
        //Create a hue value
        double value = ((double)x/map.Width)*360d;
        //Set the hue value to our sample
        pixel.Hue = value;
        //Return our sample to the PixelMap
        map[x, y] = pixel;
    }
}
//Save the PixelMap through a Bitmap
map.GetBitmap().Save("output.png");