65.9K
CodeProject is changing. Read more.
Home

Work with bitmaps faster in C#

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.89/5 (6 votes)

Aug 15, 2011

CPOL
viewsIcon

10211

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. int cCount = Depth / 8;
  5. In both SetPixel and GetPixel, replace cCount with Step:
  6. //Get start index of the specified pixel
    int i = ((y * Width) + x) * cCount;

    now becomes:

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