2011-09-14 48 views
0

如何通過設置色調,飽和度增量和亮度增量來使Android可繪製顏色?如何給drawable着色?

+0

什麼是GIMP?截圖? –

+0

我改變了這個問題,現在沒有GIMP了...無論如何,我發現如何做我想做的事,我會在測試後回答這個問題。 – fhucho

回答

1

還沒有測試過,但它應該工作。

public static BitmapDrawable colorize(BitmapDrawable d, float hue, float saturationDelta, float valueDelta) { 
    Bitmap src = d.getBitmap(); 
    Bitmap b = src.copy(Bitmap.Config.ARGB_8888, true); 
    for (int x = 0; x < b.getWidth(); x++) { 
     for (int y = 0; y < b.getHeight(); y++) { 
      int color = b.getPixel(x, y); 
      float[] hsv = new float[3]; 
      Color.colorToHSV(color, hsv); 
      hsv[0] = hue; 
      hsv[1] += saturationDelta; 
      hsv[2] += valueDelta; 
      int newColor = Color.HSVToColor(Color.alpha(color), hsv); 
      b.setPixel(x, y, newColor); 
     } 
    } 
    return new BitmapDrawable(b); 
}