# QSORT对位图颜色排序排成了这样，哪位大侠能帮我看看啊

lyp371 2013-05-01 01:54:54
``````int getCV(TColor color)
{
int r,g,b;
r=GetRValue(color);
g=GetGValue(color);
b=GetBValue(color);
return(r*0x00010000+g*0x00000100+b);
}
void qsortbmp(TBitmap *map,int left,int right)
{

if(left >= right) return;
int i = left,j = right;
int temp;
//int key = a[left];//取首元素为关键值
int key = getCV(map->Canvas->Pixels[((left + right)/2)%map->Width][int((left + right) / 2/map->Width)]);

while(i<=j)
{

while( getCV(map->Canvas->Pixels[j%map->Width][int(j/map->Width)])>key&&j>left)
j--;
while(getCV(map->Canvas->Pixels[i%map->Width][int(i/map->Width)])<key&&i<right)
i++;
if(i<=j)
{
temp = map->Canvas->Pixels[i%map->Width][int(i/map->Width)];
map->Canvas->Pixels[i%map->Width][int(i/map->Width)] = map->Canvas->Pixels[j%map->Width][int(j/map->Width)];
map->Canvas->Pixels[j%map->Width][int(j/map->Width)] = temp;
i++;
j--;
}

}
if(left<j) qsortbmp(map,left,j);
if(right>i)qsortbmp(map,i,right);
}``````

...全文
23 回复 点赞 打赏 收藏 举报

C++ Builder

1.3w+

C++ Builder相关内容讨论区

2013-05-01 01:54