2014-12-30 3 views
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: 
         (...) 
        } 

이에 대한 제안 사항이 있으십니까?

답변

1

최신 지원 v7 라이브러리에는 필요한 동급 클래스가 있습니다. 문서에서 :

V7 팔레트 지원 라이브러리 팔레트 클래스를 포함, 당신은 이미지에서 눈에 띄는 색상을 추출 할 수 있습니다

You can read more about it here.

간단한 사용 :

Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() { 
    @Override 
    public void onGenerated(Palette palette) { 
     // colors generated 
    } 
}); 
관련 문제