bitmap的图像像素遍历方法

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;
}
}
上一篇:[LeetCode] 118. 杨辉三角


下一篇:UOJ#80 二分图最大权匹配 [模板题]