本文整理匯總了Java中android.support.v7.graphics.Palette.from方法的典型用法代碼示例。如果您正苦於以下問題:Java Palette.from方法的具體用法?Java Palette.from怎麽用?Java Palette.from使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.graphics.Palette
的用法示例。
在下文中一共展示了Palette.from方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: changeColor
import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
/**
* 改變各部分的顏色
* @param position 下標
*/
private void changeColor(final int position) {
Palette.Swatch swatch = mSwatchMap.get(position);
if (swatch != null){
setColor(swatch);//設置顏色
return;
}
// 用來提取顏色的Bitmap
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),mImgResources[position]);
// Palette的部分
Palette.Builder builder = Palette.from(bitmap);
builder.generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
//獲取到充滿活力的樣本
Palette.Swatch vibrant = palette.getVibrantSwatch();
setColor(vibrant);//設置顏色
mSwatchMap.put(position,vibrant);//保存對應位置的樣本對象
}
});
}
示例2: pickPicColors
import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
public void pickPicColors() {
Bitmap bitmap = ((BitmapDrawable) mIvPic.getDrawable()).getBitmap();
Palette.Builder builder = Palette.from(bitmap);
builder.generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
//提取有活力的顏色
int vibrantColor = palette.getVibrantColor(Color.RED);
mTvVibrant.setBackgroundColor(vibrantColor);
//提取有活力的 亮色
int lightVibrantColor = palette.getLightVibrantColor(Color.RED);
mTvLightVibrant.setBackgroundColor(lightVibrantColor);
//提取有活力的 暗色
int darkVibrantColor = palette.getDarkVibrantColor(Color.RED);
mTvDarkVibrant.setBackgroundColor(darkVibrantColor);
//提取柔和的顏色
int mutedColor = palette.getMutedColor(Color.RED);
mTvMuted.setBackgroundColor(mutedColor);
//提取柔和的亮色
int lightMutedColor = palette.getLightMutedColor(Color.RED);
mTvLightMuted.setBackgroundColor(lightMutedColor);
//提取柔和的暗色
int darkMutedColor = palette.getDarkMutedColor(Color.RED);
mTvDarkMuted.setBackgroundColor(darkMutedColor);
Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();//獲取有活力的顏色樣本
Palette.Swatch lightVibrantSwatch = palette.getLightVibrantSwatch();//獲取有活力 亮色的樣本
Palette.Swatch drakVibrantSwatch = palette.getDarkVibrantSwatch();//獲取有活力 暗色的樣本
Palette.Swatch mutedSwatch = palette.getMutedSwatch();//獲取柔和的顏色樣本
Palette.Swatch lightMutedSwatch = palette.getLightMutedSwatch();//獲取柔和 亮色的樣本
Palette.Swatch darkMutedSwatch = palette.getDarkMutedSwatch();//獲取柔和 暗色的樣本
// int rgb = vibrantSwatch.getRgb();//獲取對應樣本的rgb
// float[] hsl = vibrantSwatch.getHsl();//獲取hsl顏色
// int population = vibrantSwatch.getPopulation();//獲取像素的數量
// int titleTextColor = vibrantSwatch.getTitleTextColor();//獲取適合標題文字的顏色
// int bodyTextColor = vibrantSwatch.getBodyTextColor();//獲取適配內容文字的顏色
//獲取適合標題文字的顏色
int titleTextColor = drakVibrantSwatch.getTitleTextColor();
mTvTitle.setTextColor(titleTextColor);
;
//獲取適合內容文字的顏色
int bodyTextColor = drakVibrantSwatch.getBodyTextColor();
mTvBody.setTextColor(bodyTextColor);
}
});
}
示例3: onCreate
import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_palette);
mIvPic = (ImageView) findViewById(R.id.ivPic);
mTvBody = (TextView) findViewById(R.id.tvBody);
mTvTitle = (TextView) findViewById(R.id.tvTitle);
mTvDarkMutedColor = (TextView) findViewById(R.id.tvDarkMutedColor);
mTvLightMutedColor = (TextView) findViewById(R.id.tvLightMutedColor);
mTvDarkVibrantColor = (TextView) findViewById(R.id.tvDarkVibrantColor);
mTvLightVibrantColor = (TextView) findViewById(R.id.tvLightVibrantColor);
mTvMutedColor = (TextView) findViewById(R.id.tvMutedColor);
mTvVibrantColor = (TextView) findViewById(R.id.tvVibrantColor);
BitmapDrawable drawable = (BitmapDrawable) mIvPic.getDrawable();
Bitmap bitmap = drawable.getBitmap();
Palette.Builder builder = Palette.from(bitmap);
builder.maximumColorCount(32); // 構建Palette時使用的最大顏色數,默認是16,風景圖推薦取值8-16,人臉圖像推薦取值24-32(值越大,花費的時間越長,可選擇的色彩越多)
// .setRegion(0, 0, bitmap.getWidth() - 1, bitmap.getHeight()) // 設置Palette顏色分析的圖像區域
// .addFilter(new Palette.Filter() { // 設置過濾器來過濾不需要的顏色(目前還不清楚怎麽用,網上也找不到任何教程及代碼,無從學習~)
// @Override
// public boolean isAllowed(int rgb, float[] hsl) {
// return false;
// }
// })
// .clearRegion()
// .clearFilters();
builder.generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
// 暗、柔和
int darkMutedColor = palette.getDarkMutedColor(Color.BLACK);
// 亮、柔和
int lightMutedColor = palette.getLightMutedColor(Color.BLACK);
// 暗、鮮豔
int darkVibrantColor = palette.getDarkVibrantColor(Color.BLACK);
// 亮、鮮豔
int lightVibrantColor = palette.getLightVibrantColor(Color.BLACK);
// 柔和
int mutedColor = palette.getMutedColor(Color.BLACK);
// 鮮豔
int vibrantColor = palette.getVibrantColor(Color.BLACK);
// 獲取某種色調的樣品(這裏指柔和的暗色)
Palette.Swatch darkMutedSwatch = palette.getDarkMutedSwatch();
// 獲取圖片的整體顏色rgb混合值---主色調
int rgb = darkMutedSwatch.getRgb();
// 獲取圖片中間的文字顏色
int bodyTextColor = darkMutedSwatch.getBodyTextColor();
// 獲取作為標題的顏色(有一定的和圖片的對比度的顏色值)
int titleTextColor = darkMutedSwatch.getTitleTextColor();
// 顏色向量
float[] hsl = darkMutedSwatch.getHsl();
// 分析該顏色在圖片中所占像素值
int population = darkMutedSwatch.getPopulation();
mTvBody.setBackgroundColor(generateTransparentColor(0.2f, rgb));
mTvBody.setTextColor(bodyTextColor);
mTvTitle.setBackgroundColor(generateTransparentColor(0.6f, rgb));
mTvTitle.setTextColor(titleTextColor);
mTvDarkMutedColor.setBackgroundColor(darkMutedColor);
mTvLightMutedColor.setBackgroundColor(lightMutedColor);
mTvDarkVibrantColor.setBackgroundColor(darkVibrantColor);
mTvLightVibrantColor.setBackgroundColor(lightVibrantColor);
mTvMutedColor.setBackgroundColor(mutedColor);
mTvVibrantColor.setBackgroundColor(vibrantColor);
}
});
}
示例4: onResourceReady
import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
/**
* Called when a load completes successfully, immediately after
* {@link Target#onResourceReady(Object, GlideAnimation)}.
*
* @param resource The resource that was loaded for the target.
* @param model The specific model that was used to load the image.
* @param target The target the model was loaded into.
* @param isFromMemoryCache True if the load completed synchronously (useful for determining whether or not to
* animate)
* @param isFirstResource True if this is the first resource to in this load to be loaded into the target. For
* example when loading a thumbnail and a fullsize image, this will be true for the first
* image to load and false for the second.
* @return True if the listener has handled setting the resource on the target (including any animations), false to
* allow Glide's request to update the target (again including animations).
*/
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
try {
Palette.Builder mBuilder = Palette.from(((GlideBitmapDrawable) resource.getCurrent()).getBitmap());
mBuilder.generate(this);
} catch (ClassCastException ex) {
ex.printStackTrace();
}
return false;
}