use of android.graphics.drawable.BitmapDrawable in project AndroidPicker by gzu-liyujiang.
the class ConvertUtils method toBitmap.
/**
* 将Drawable转换为Bitmap
* 参考:http://kylines.iteye.com/blog/1660184
*/
public static Bitmap toBitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
} else if (drawable instanceof ColorDrawable) {
//color
Bitmap bitmap = Bitmap.createBitmap(32, 32, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(((ColorDrawable) drawable).getColor());
return bitmap;
} else if (drawable instanceof NinePatchDrawable) {
//.9.png
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
return null;
}
use of android.graphics.drawable.BitmapDrawable in project ListenerMusicPlayer by hefuyicoder.
the class PanelSlideListener method setBlurredAlbumArt.
private void setBlurredAlbumArt() {
Observable.create(new Observable.OnSubscribe<Drawable>() {
@Override
public void call(Subscriber<? super Drawable> subscriber) {
Bitmap bitmap = ((BitmapDrawable) albumImage.getDrawable()).getBitmap();
Drawable drawable = ImageUtil.createBlurredImageFromBitmap(bitmap, mContext, 3);
subscriber.onNext(drawable);
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Drawable>() {
@Override
public void call(Drawable drawable) {
CoordinatorLayout.LayoutParams imageLayout = (CoordinatorLayout.LayoutParams) albumImage.getLayoutParams();
imageLayout.height = FrameLayout.LayoutParams.MATCH_PARENT;
imageLayout.width = FrameLayout.LayoutParams.MATCH_PARENT;
albumImage.setLayoutParams(imageLayout);
albumImage.setImageDrawable(drawable);
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
ColorDrawable colorDrawable = new ColorDrawable(nowPlayingCardColor);
colorDrawable.setAlpha(200);
albumImage.setForeground(colorDrawable);
}
}
});
}
use of android.graphics.drawable.BitmapDrawable in project ListenerMusicPlayer by hefuyicoder.
the class ImageUtil method createBlurredImageFromBitmap.
public static Drawable createBlurredImageFromBitmap(Bitmap bitmap, Context context, int inSampleSize) {
RenderScript rs = RenderScript.create(context);
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = inSampleSize;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imageInByte = stream.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);
Bitmap blurTemplate = BitmapFactory.decodeStream(bis, null, options);
final android.support.v8.renderscript.Allocation input = android.support.v8.renderscript.Allocation.createFromBitmap(rs, blurTemplate);
final android.support.v8.renderscript.Allocation output = android.support.v8.renderscript.Allocation.createTyped(rs, input.getType());
final android.support.v8.renderscript.ScriptIntrinsicBlur script = android.support.v8.renderscript.ScriptIntrinsicBlur.create(rs, android.support.v8.renderscript.Element.U8_4(rs));
script.setRadius(4f);
script.setInput(input);
script.forEach(output);
output.copyTo(blurTemplate);
return new BitmapDrawable(context.getResources(), blurTemplate);
}
use of android.graphics.drawable.BitmapDrawable in project NotificationPeekPort by lzanita09.
the class AppearanceSettingsFragment method initPreviewBackgroundDrawable.
/**
* Create a new {@link android.graphics.drawable.TransitionDrawable} object with correct order
* of Drawables based on user selection.
*
* @return TransitionDrawable object created.
*/
private TransitionDrawable initPreviewBackgroundDrawable() {
boolean isWallpaperSelected = WallpaperFactory.isWallpaperThemeSelected(getActivity());
Drawable black = new ColorDrawable(Color.BLACK);
Drawable wallpaper = mUseLiveWallpaper ? new ColorDrawable(Color.TRANSPARENT) : new BitmapDrawable(getResources(), mWallpaperFactory.getPrefSystemWallpaper());
mChangeDrawables = !isWallpaperSelected ? new Drawable[] { black, wallpaper } : new Drawable[] { wallpaper, black };
mBlackDrawableIndex = !isWallpaperSelected ? 0 : 1;
return new TransitionDrawable(mChangeDrawables);
}
use of android.graphics.drawable.BitmapDrawable in project robolectric by robolectric.
the class ShadowDrawable method createFromStream.
@Implementation
public static Drawable createFromStream(InputStream is, String srcName) {
if (corruptStreamSources.contains(srcName)) {
return null;
}
BitmapDrawable drawable = new BitmapDrawable(ReflectionHelpers.callConstructor(Bitmap.class));
shadowOf(drawable).createdFromInputStream = is;
shadowOf(drawable).drawableCreateFromStreamSource = srcName;
// start off not invalidated
shadowOf(drawable).validate();
return drawable;
}
Aggregations