1
我正在顯示從服務器獲取的每個圖像的佈局背景圖像,並且它工作正常。我需要佈局背景圖像以模糊。我爲此寫了一堂課。如何從調色板API中選取模糊顏色android
我的問題是: 如何從調色板API中選取模糊顏色?
Bluer.java
public class BlurBuilder {
private static final float BITMAP_SCALE = 0.4f;
private static final float BLUR_RADIUS = 7.5f;
public static Bitmap blur(Context context, Bitmap image) {
int width = Math.round(image.getWidth() * BITMAP_SCALE);
int height = Math.round(image.getHeight() * BITMAP_SCALE);
Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
RenderScript rs = RenderScript.create(context);
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
theIntrinsic.setRadius(BLUR_RADIUS);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}
}
MainActivity.java
final LinearLayout mMainLayout = (LinearLayout)findViewById(R.id.revi_main_layout);
target = new Target() {
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
mMainLayout.setBackground(new BitmapDrawable(bitmap));
Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
public void onGenerated(Palette palette) {
movie_image.setImageBitmap(bitmap);
int defaultColor = getResources().getColor(R.color.whiteColor);
toolbar.setBackgroundColor(palette.getLightVibrantColor(defaultColor));
toolbar.setTitleTextColor(palette.getDarkMutedColor(defaultColor));
toolbar.setTitle(getString(R.string.title_activity_news_update_fulldec));
}
});
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
Picasso.with(getApplicationContext()).load((Reviews_update.revData.get(mov_pos))
.getNewsImage()).into(target);
請幫助我如何模糊我的佈局的背景圖像,從調色板API模糊的顏色嗎?
謝謝你提前