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;
[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;
相关文章推荐
- C# 的高效方法取得图片的像素区数据
- 高效取得图片数据GetImgByte,返回结果数组和像素一一对应
- 一种基于重载的高效c#上图片添加文字图形图片的方法
- C#中高效的数据插入方法
- C#中加载图片与读取图片上的像素点方法
- 用C#编程从数据库中读取图片数据导进Excel文件的方法(如何从数据库中读取保存的文件,直接打开,中间不保存到本地)
- c#使用Web服务返回图片数据的方法
- 用C#编程从数据库中读取图片数据导进Excel文件的方法
- C#远程发送和接收数据流生成图片的方法
- 用C#编程从数据库中读取图片数据导进Excel文件的方法(如何从数据库中读取保存的文件,直接打开,中间不保存到本地)
- C#实现图片放大功能的按照像素放大图像方法
- 高效取图片像素的方法
- C# 高效过滤DataTable 中重复数据方法
- 用C#编程从数据库中读取图片数据导进Excel文件的方法
- 使用Excel“自动化”功能将数据输出到Excel的三种高效方法对比实验
- [原创]c#编写-获取Infopath数据中的图片工具
- C#向Excel报表中插入图片的2种方法
- C#向Excel报表中插入图片的2种方法
- c# : 无刷新取得远程数据
- 用C#读取图片的EXIF信息的方法