public class FastBitmap
{
    BitmapData bitmapData;
    public FastBitmap(Bitmap bitmap)
    {
        this.bitmapData=bitmap.LockBits(new Rectangle(0,0,bitmap.Width,bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bitmap.PixelFormat);
    }
    public unsafe Color GetPixel(int x,int y)
    {
        if (bitmapData.PixelFormat == PixelFormat.Format32bppRgb || bitmapData.PixelFormat == PixelFormat.Format32bppArgb)
        {
            byte* numPtr = (byte*)((int)bitmapData.Scan0 + y * bitmapData.Stride + x * 4);
            return Color.FromArgb(numPtr[3],numPtr[2], numPtr[1],numPtr[0]);
        }
        if (bitmapData.PixelFormat == PixelFormat.Format24bppRgb)
        {
            byte* numPtr2 = (byte*)((int)bitmapData.Scan0 + y * bitmapData.Stride + x * 3);
            return Color.FromArgb(numPtr2[2], numPtr2[1], numPtr2[0]);
        }
        return Color.Empty;
    }
}

 

相关文章:

  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-24
  • 2021-07-29
  • 2021-05-29
  • 2021-03-30
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案