getting access to actual pixels in hbitmap object returned by GetHBitmap() using c#

I am programming in c#.
I need to change the alpha value of every pixel in a Bitmap.

I did this:

for(row = 1; row < myBitmap.Size.Height; row++)
     for(col = 1; col < myBitmap.Size.Width; col++)
      Color aColor = myBitmap.GetPixel(col, row);
      aColor = Color.FromArgb(alpha, aColor);
      myBitmap.SetPixel(col, row, aColor);

which works but it is too slow.  i want to access the actual pixels via the bmBits pointer in the HBitmap returned from myBitmap.GetHbitmap() but I do not know how to do this.  Can you show me how to at least get a bmBits pointer that I can increment over the range of the bitmap?  I can figure out the rest.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can access bitmap bits directly using Bitmap.LockBits functopn and unsafe pointers.

For example, this function inverts all pixels in the bitmap:

public static bool Invert(Bitmap b)
    // GDI+ still lies to us - the return format is BGR, NOT RGB.
    BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height),
        ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
    int stride = bmData.Stride;
    System.IntPtr Scan0 = bmData.Scan0;
        byte * p = (byte *)(void *)Scan0;
        int nOffset = stride - b.Width*3;
        int nWidth = b.Width * 3;
        for(int y=0;y < b.Height;++y)
            for(int x=0; x < nWidth; ++x )
                p[0] = (byte)(255-p[0]);
            p += nOffset;


    return true;

See details in the article.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
loring_vogelAuthor Commented:
Thanks that is excellent!

I appreciate the completeness of the answer.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.