19,469
社区成员
发帖
与我相关
我的任务
分享
//1. 加载jpg,这个网上源很多,嫌麻烦就把JPG转成BMP,然后LoadImage()
//2.
// 假设 宽width 高height 32位 每个直方柱宽 cx, 直方柱数 #define NUM 8
// 假定已经取得图像数据 lpBits(不是头,是真正的图像数据)
Begin()
{
float result[NUM];
for(int i=0; i< NUM; i++)
{
result[i] = GetPart(i);
}
}
float GetPart(int i)
{
int xx = i*cx + cx/2;
int red, green, blue; // *1
for(int j=0; j< height; j++)
{
if(j == 0)
{
blue = *(lpBits+j*width*4+xx*4); // *2
green = *(lpBits+j*width*4+xx*4+1);
red = *(lpBits+j*width*4+xx*4+2);
continue;
}
if(blue != *(lpBits+j*width*4+xx*4) || // *3
green != *(lpBits+j*width*4+xx*4+1) ||
red != *(lpBits+j*width*4+xx*4+2))
return ((float)(height-j))/(float)height;
}
if(j == height)
return 0.0f; // *4
}
// *1 怎样取得r,g,b值,如果你的图上画100%刚好与图像一样高就无法得到底色这样就不能分别100%与
// 0%,所以图像最好上部有空余部分或已经知道了底色(除非你确定没有100%与0%)。
// *2 这里是取底色(如果已经知道了可以去掉),如果是24位 要乘3
// *3 这里是比较,如果图像有噪声且没有做去噪处理,这里要加误差 如abs(blue - *(lpBits+j*width*4+xx*4)) > 10
// (差值在10以内认为是同一种色)
// *4 如*1所述,100%与0%的区别问题