Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Work with bitmaps faster in C#

0.00/5 (No votes)
15 Aug 2011 1  
You can increase the speed of both SetPixel and GetPixel by doing the following:Add the line 'int step = 0' at the LockBitmap class level.Remove 'int' declation of 'step' in the LockBits method and calculate as is.In both SetPixel and GetPixel, remove the line:int cCount = Depth /...

You can increase the speed of both SetPixel and GetPixel by doing the following:



  1. Add the line 'int step = 0' at the LockBitmap class level.
  2. Remove 'int' declation of 'step' in the LockBits method and calculate as is.
  3. In both SetPixel and GetPixel, remove the line:
  4. C#
    int cCount = Depth / 8;

  5. In both SetPixel and GetPixel, replace cCount with Step:
  6. C#
    //Get start index of the specified pixel
    int i = ((y * Width) + x) * cCount;

    now becomes:


    C#
    //Get start index of the specified pixel
    int i = ((y * Width) + x) * Step;

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here