FastPixel

Andrew Vos created a nice VB.NET class called FastPixel which will copy a bitmap to an array of the single bytes which can then be modified through the well-known SetPixel, GetPixel and Clear methods. Since these are now only some in-memory operations it is blazing fast compared to the standard functions.

Someone posted a C# version in the comments which had problems with bitmaps with an odd row count. I searched the net and found some replacement code to use instead. The only drawback is, that the new code is unsafe code.

Download the source code here: fastpixel.cs (4.64 KiB, 45 downloads)

Usage

Bitmap myBitmap = new Bitmap(100, 100, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
FastPixel fp = new FastPixel(myBitmap);
fp.Lock();   // copies bitmap to array and locks it
fp.Clear(Color.White);
fp.SetPixel(10, 10, Color.Black);
// ... do some more ...
fp.Unlock(true);  // true = write array to bitmap

 
snippets/c-sharp/fastpixel.txt · Last modified: 2009-01-30 02:06.06 by mbirth
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki Contents powered by Club-Mate Contents powered by BassDrive.com Labelled with ICRA