How can I copy the pixel data from a Bitmap with negative stride?

前端 未结 5 1573
眼角桃花
眼角桃花 2020-12-11 06:45

I was looking for the fastest way to convert a Bitmap to 8bpp. I found 2 ways:

1.

        public static System.Drawing.Image Conver         


        
5条回答
  •  伪装坚强ぢ
    2020-12-11 07:20

    I don't know why there is something strange about the Bitmap created by the FromHbitmap method, but I do know that you can fix it by using Bitmap bmpClone = (Bitmap)bmp.Clone(); and doing the LockBits on bmpClone.

    Also, I found that if you use bmp.Clone(), you cannot Dispose() of bmp until you have finished with the clone.

    This also works and let's you dispose of the negative stride image sooner rather than later:

            Bitmap bmp = null;
            using (Bitmap bmpT = CopyToBpp(bmpO, 1))
            {
                bmp = new Bitmap(bmpT);
            }
    

提交回复
热议问题