是否有適用於Android的API,可讓您提取主要背景顏色以創建透明覆蓋圖,以便我可以在其上編寫文本。用於提取背景顏色的材質設計API
例如,如果4張圖像的主色爲棕色,則覆蓋層爲透明棕色。
我期待創建類似以下圖像的東西,以在圖片頂部添加信息。它來自Google播放音樂。
謝謝
是否有適用於Android的API,可讓您提取主要背景顏色以創建透明覆蓋圖,以便我可以在其上編寫文本。用於提取背景顏色的材質設計API
例如,如果4張圖像的主色爲棕色,則覆蓋層爲透明棕色。
我期待創建類似以下圖像的東西,以在圖片頂部添加信息。它來自Google播放音樂。
謝謝
有可能是一個解決方案:
我假設你把4的ImageView在RelativeLayout的(稱爲parentLyt)
RelativeLayout view = (RelativeLayout) findViewById(R.id.parentLyt);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
現在你可以讓你的4個圖像的位圖:
Bitmap bitmap = view.getDrawingCache();
並通過此位圖使用Palette API:
Palette colorPalette = Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
public void onGenerated(Palette palette) {
int color = palette.getLightVibrantSwatch().getRgb();
// Do something with colors...just for example :
// Convert to hex format and add 88 alpha channel "#88RRGGBB"
String transparentColor = String.format("#88%06X", 0xFFFFFF & intColor);
// Convert back to Color object aka int
int finalColor = Color.parseColor(transparentColor);
}
});
你應該看看新的[Palette API](https://developer.android.com/reference/android/support/v7/graphics/Palette.html)和[there](https://developer.android .com/training/material/drawables.html#ColorExtract)是這個API函數的總和 – 2014-11-03 12:14:31
謝謝!!這就是我正在尋找:) – wheeliez 2014-11-03 12:20:46
我創建了一個答案,這是一個簡單的例子,你可以如何使用它來解決你的PB;) – 2014-11-03 12:27:48