标签:style blog color ar for sp 数据 div art
这种方式效率很低, 因为每次调用getpixel,都包含着程序的进栈和出栈。所以,面对大量需要处理的数据,采用直接访问内存地址的方法。
用两种方法对同一张图片(3264*2448像素)进行处理,前者需要1分钟,后者只需1秒左右。
所以,后者比前者至少快60倍
直接访问内存地址的另一种方式:
int i,j,temp;
int pixel[4];
int width = yuantu.GetWidth();
int height = yuantu.GetHeight();
int widthBytes = yuantu.GetPitch();
bianyuantu.Create(width,height,yuantu.GetBPP());
if(yuantu.IsIndexed())
{
yuantu.GetColorTable(0,256,colorTable);
bianyuantu.SetColorTable(0,256,colorTable);
}
BYTE *pYuantuData = (BYTE*)yuantu.GetBits();
BYTE *pBianyuantuData =(BYTE*)bianyuantu.GetBits();
for(j=0;j<height-1;j++)
{
for(i=0;i<width-1;i++)
{
pixel[0]=pYuantuData[j*widthBytes+i];
pixel[1]=pYuantuData[j*widthBytes+i+1];
pixel[2]=pYuantuData[(j+1)*widthBytes+i];
pixel[3]=pYuantuData[(j+1)*widthBytes+i+1];
temp=(int)sqrt((double)((pixel[0]-pixel[3])*(pixel[0]-pixel[3])
+(pixel[1]-pixel[2])*(pixel[1]-pixel[2]))); //罗伯特算子
pBianyuantuData[j*widthBytes+i]=temp;
}
}
//真彩色图像变为灰度图,直接修改像素点的值
//非真彩色图像变为灰度图,修改调色板信息
标签:style blog color ar for sp 数据 div art
原文地址:http://www.cnblogs.com/qxzy/p/4035829.html