0
我得到一個由用戶繪製的位圖,並嘗試通過執行您可以在下面看到的方式從中提取突出的顏色,但它似乎不起作用。Android搜索位圖的突出顏色
final Map<Integer, Integer> getColorsFromImage;
{
int mostlyUsed = 0;
final int widthInPx = drawView.getDrawingCache().getWidth();
final int heightInPx = drawView.getDrawingCache().getHeight();
Map<Integer, Integer> colors = new HashMap<Integer, Integer>(); // rgb
int count = 0;
int currentColor = 0;
for(int x = 0; x < widthInPx; x++){
for(int y = 0; y < heightInPx; y++){
count = 0;
currentColor = drawView.getDrawingCache().getPixel(widthInPx, heightInPx);
if(colors.containsKey(currentColor)){
count = colors.get(currentColor) + 1;
}
if (count > mostlyUsed) {
mostlyUsed = count;
}
colors.put(currentColor, count);
count = 0;
}
}
Integer mostlyUsedColor = colors.get(mostlyUsed);
switch (mostlyUsedColor){
case #A52A2A:
do sth;
break;
case #FFFFFF:
(...)
}
你有什麼建議嗎?