您的位置:首页 > 编程语言 > C#

C# 的高效方法取得图片的像素区数据

2017-12-27 20:01 148 查看
http://blog.csdn.net/zh_geo/article/details/46239439



[csharp] view
plain copy

// Lock the bitmap's bits.    

Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);  

BitmapData bmpData = image.LockBits(rect, ImageLockMode.ReadWrite, image.PixelFormat);  

// Get the address of the first line.  

IntPtr ptr = bmpData.Scan0;  

// Declare an array to hold the bytes of the bitmap.  

int bytes = Math.Abs(bmpData.Stride) * image.Height;  

byte[] rgbValues = new byte[bytes];  

// Copy the RGB values into the array.  

Marshal.Copy(ptr, rgbValues, 0, bytes);  

// Unlock the bits.  

image.UnlockBits(bmpData);  

return rgbValues;  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: