public class FastBitmap
{
BitmapData bitmapData;
public FastBitmap(Bitmap bitmap)
{
this.bitmapData=bitmap.LockBits(new Rectangle(,,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 * );
return Color.FromArgb(numPtr[],numPtr[], numPtr[],numPtr[]);
}
if (bitmapData.PixelFormat == PixelFormat.Format24bppRgb)
{
byte* numPtr2 = (byte*)((int)bitmapData.Scan0 + y * bitmapData.Stride + x * );
return Color.FromArgb(numPtr2[], numPtr2[], numPtr2[]);
}
return Color.Empty;
}
}