标签:
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; } }
标签:
原文地址:http://www.cnblogs.com/zhayunjia/p/5076048.html