高效取图片像素的方法
2013-11-21 17:08
148 查看
public static short
![](http://img.baidu.com/img/iknow/qb/select-search.png)
[][] GetPixs(Bitmap bitmap)
{
int height = bitmap.Height;
int width = bitmap.Width;
byte tempB, tempG, tempR;
short[][] spOriginData = new short[height][];
for (int i = 0; i < height; i++)
{
spOriginData[i] = new short[width];
}
BitmapData dataOut = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int offset = dataOut.Stride - dataOut.Width * 3;
try
{
unsafe
{
byte* pOut = (byte*)(dataOut.Scan0.ToPointer());
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
tempB = pOut[0];
tempG = pOut[1];
tempR = pOut[2];
double data=0.31 * tempR + 0.59 * tempG + 0.11 * tempB;
if (data > 255)
spOriginData[y][x] = 255;
else
if (data < 0)
spOriginData[y][x] = 0;
else
spOriginData[y][x] = (short)data;
pOut += 3;
}
pOut += offset;
}
bitmap.UnlockBits(dataOut);
}
}
catch
{
}
return spOriginData;
}
![](http://img.baidu.com/img/iknow/qb/select-search.png)
[][] GetPixs(Bitmap bitmap)
{
int height = bitmap.Height;
int width = bitmap.Width;
byte tempB, tempG, tempR;
short[][] spOriginData = new short[height][];
for (int i = 0; i < height; i++)
{
spOriginData[i] = new short[width];
}
BitmapData dataOut = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int offset = dataOut.Stride - dataOut.Width * 3;
try
{
unsafe
{
byte* pOut = (byte*)(dataOut.Scan0.ToPointer());
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
tempB = pOut[0];
tempG = pOut[1];
tempR = pOut[2];
double data=0.31 * tempR + 0.59 * tempG + 0.11 * tempB;
if (data > 255)
spOriginData[y][x] = 255;
else
if (data < 0)
spOriginData[y][x] = 0;
else
spOriginData[y][x] = (short)data;
pOut += 3;
}
pOut += offset;
}
bitmap.UnlockBits(dataOut);
}
}
catch
{
}
return spOriginData;
}
相关文章推荐
- C# 的高效方法取得图片的像素区数据
- C# 的高效方法取得图片的像素区数据
- android 通过bitmapfactory得到图片真实像素的方法,以及没有得到真实像素的原因
- Android压缩图片到100K以下并保持不失真的高效方法
- ios设置导航栏透明方法:使用只有一个像素点的透明图片,通过以下代码即可
- Android高效压缩图片不失真的方法总结
- Android一种高效压缩图片的方法
- IE6下图片下方有2个像素空隙的解决方法
- Android压缩图片到100K以下并保持不失真的高效方法
- Android压缩图片到100K以下并保持不失真的高效方法
- Android压缩图片到100K以下并保持不失真的高效方法
- Android压缩图片到100K以下并保持不失真的高效方法
- 【Python+OpenCV】图片局部区域像素值处理(改进版)-一种特征提取方法
- java编程简单获取图片像素的方法
- Android压缩图片到100K以下并保持不失真的高效方法
- Android压缩图片到100K以下并保持不失真的高效方法
- php实现高效获取图片尺寸的方法
- 从像素生成图片的方法
- Android压缩图片到100K以下并保持不失真的高效方法
- opencv访问图片中像素的方法(三)——动态地址计算