Search in sources :

Example 31 with BitmapDrawable

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;
}
Also used : Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) Canvas(android.graphics.Canvas) BitmapDrawable(android.graphics.drawable.BitmapDrawable) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable)

Example 32 with BitmapDrawable

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);
            }
        }
    });
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) Subscriber(rx.Subscriber) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 33 with BitmapDrawable

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);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) BitmapDrawable(android.graphics.drawable.BitmapDrawable) RenderScript(android.support.v8.renderscript.RenderScript) Bitmap(android.graphics.Bitmap) ByteArrayInputStream(java.io.ByteArrayInputStream) BitmapFactory(android.graphics.BitmapFactory)

Example 34 with BitmapDrawable

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);
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 35 with BitmapDrawable

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;
}
Also used : Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Implementation(org.robolectric.annotation.Implementation)

Aggregations

BitmapDrawable (android.graphics.drawable.BitmapDrawable)640 Bitmap (android.graphics.Bitmap)426 Drawable (android.graphics.drawable.Drawable)187 Canvas (android.graphics.Canvas)182 Paint (android.graphics.Paint)110 Rect (android.graphics.Rect)77 View (android.view.View)77 ImageView (android.widget.ImageView)63 ColorDrawable (android.graphics.drawable.ColorDrawable)59 TextView (android.widget.TextView)51 IOException (java.io.IOException)40 Resources (android.content.res.Resources)35 LayerDrawable (android.graphics.drawable.LayerDrawable)33 AnimationDrawable (android.graphics.drawable.AnimationDrawable)30 File (java.io.File)27 Test (org.junit.Test)24 Matrix (android.graphics.Matrix)23 Intent (android.content.Intent)22 StateListDrawable (android.graphics.drawable.StateListDrawable)22 InputStream (java.io.InputStream)22