Click here to Skip to main content
15,886,034 members
Articles / Multimedia / Image Processing
Alternative
Tip/Trick

Work with bitmaps faster in C#

Rate me:
Please Sign up or sign in to vote.
4.89/5 (6 votes)
15 Aug 2011CPOL 9.9K   3   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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer n/a
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questiona good example will be helpful Pin
Southmountain4-Jul-22 7:46
Southmountain4-Jul-22 7:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.