Java 类android.graphics.drawable.BitmapDrawable 实例源码

项目:QMUI_Android    文件:QMUIDrawableHelper.java   
/**
 * 从一个view创建Bitmap。
 * 注意点:绘制之前要清掉 View 的焦点,因为焦点可能会改变一个 View 的 UI 状态。
 * 来源:https://github.com/tyrantgit/ExplosionField
 *
 * @param view  传入一个 View,会获取这个 View 的内容创建 Bitmap。
 * @param scale 缩放比例,对创建的 Bitmap 进行缩放,数值支持从 0 到 1。
 */
public static Bitmap createBitmapFromView(View view, float scale) {
    if (view instanceof ImageView) {
        Drawable drawable = ((ImageView) view).getDrawable();
        if (drawable != null && drawable instanceof BitmapDrawable) {
            return ((BitmapDrawable) drawable).getBitmap();
        }
    }
    view.clearFocus();
    Bitmap bitmap = createBitmapSafely((int) (view.getWidth() * scale),
            (int) (view.getHeight() * scale), Bitmap.Config.ARGB_8888, 1);
    if (bitmap != null) {
        synchronized (sCanvas) {
            Canvas canvas = sCanvas;
            canvas.setBitmap(bitmap);
            canvas.save();
            canvas.drawColor(Color.WHITE); // 防止 View 上面有些区域空白导致最终 Bitmap 上有些区域变黑
            canvas.scale(scale, scale);
            view.draw(canvas);
            canvas.restore();
            canvas.setBitmap(null);
        }
    }
    return bitmap;
}
项目:QiangHongBao    文件:BitmapUtils.java   
/**
 * 从视图创建位图
 * @param view
 * @return
 */
public static Bitmap createBitmapFromView(View view) {
    if (view instanceof ImageView) {
        Drawable drawable = ((ImageView) view).getDrawable();
        if (drawable != null && drawable instanceof BitmapDrawable) {
            return ((BitmapDrawable) drawable).getBitmap();
        }
    }
    view.clearFocus();
    Bitmap bitmap = createBitmapSafely(view.getWidth(),
            view.getHeight(), Bitmap.Config.ARGB_8888, 1);
    if (bitmap != null) {
        synchronized (sCanvas) {
            Canvas canvas = sCanvas;
            canvas.setBitmap(bitmap);
            view.draw(canvas);
            canvas.setBitmap(null);
        }
    }
    return bitmap;
}
项目:From-design-to-Android-part1    文件:OrderDialogFragment.java   
private Drawable createProductImageDrawable(Product product) {
    final ShapeDrawable background = new ShapeDrawable();
    background.setShape(new OvalShape());
    background.getPaint().setColor(ContextCompat.getColor(getContext(), product.color));

    final BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(),
        BitmapFactory.decodeResource(getResources(), product.image));

    final LayerDrawable layerDrawable = new LayerDrawable
        (new Drawable[]{background, bitmapDrawable});

    final int padding = (int) getResources().getDimension(R.dimen.spacing_huge);
    layerDrawable.setLayerInset(1, padding, padding, padding, padding);

    return layerDrawable;
}
项目:MyFlightbookAndroid    文件:MFBImageInfo.java   
protected void onPostExecute(Drawable d) {
    if (d != null) {
        if (imgView != null)
            imgView.setImageDrawable(d);
        BitmapDrawable bd = (BitmapDrawable) d;
        Bitmap bmp = bd.getBitmap();
        ByteArrayOutputStream s = new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, s);
        if (mFIsThumbnail)
            m_imgThumb = s.toByteArray();
        else
            m_imgData = s.toByteArray();

        if (m_icc != null)
            m_icc.imgCompleted(MFBImageInfo.this);
    }
}
项目:SimpleUILauncher    文件:Utilities.java   
/**
 * Badges the provided icon with the user badge if required.
 */
public static Bitmap badgeIconForUser(Bitmap icon,  UserHandleCompat user, Context context) {
    if (Utilities.ATLEAST_LOLLIPOP && user != null
            && !UserHandleCompat.myUserHandle().equals(user)) {
        BitmapDrawable drawable = new FixedSizeBitmapDrawable(icon);
        Drawable badged = context.getPackageManager().getUserBadgedIcon(
                drawable, user.getUser());
        if (badged instanceof BitmapDrawable) {
            return ((BitmapDrawable) badged).getBitmap();
        } else {
            return createIconBitmap(badged, context);
        }
    } else {
        return icon;
    }
}
项目:andcouchbaseentity    文件:RoundImageView.java   
@Override
protected void onDraw(Canvas canvas) {
    Drawable drawable = getDrawable();
    if (drawable instanceof BitmapDrawable) {
        RectF rectF = new RectF(drawable.getBounds());
        int restoreCount = canvas.saveLayer(rectF, null, Canvas.ALL_SAVE_FLAG);
        getImageMatrix().mapRect(rectF);

        Paint paint = ((BitmapDrawable) drawable).getPaint();
        paint.setAntiAlias(true);
        paint.setColor(0xff000000);

        canvas.drawARGB(0, 0, 0, 0);
        canvas.drawRoundRect(rectF, RADIUS, RADIUS, paint);

        Xfermode restoreMode = paint.getXfermode();
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        super.onDraw(canvas);

        // Restore paint and canvas
        paint.setXfermode(restoreMode);
        canvas.restoreToCount(restoreCount);
    } else {
        super.onDraw(canvas);
    }
}
项目:ImageFrame    文件:ImageFrameCustomView.java   
public void startImageFrame(final ImageFrameHandler imageFrameHandler) {
  if (this.imageFrameHandler == null) {
    this.imageFrameHandler = imageFrameHandler;
  }else{
    this.imageFrameHandler.stop();
    this.imageFrameHandler = imageFrameHandler;
  }
  imageFrameHandler.setOnImageLoaderListener(new ImageFrameHandler.OnImageLoadListener() {
    @Override
    public void onImageLoad(BitmapDrawable drawable) {
      ViewCompat.setBackground(ImageFrameCustomView.this, drawable);
    }

    @Override
    public void onPlayFinish() {

    }
  });
  post(new Runnable() {
    @Override
    public void run() {
      imageFrameHandler.start();
    }
  });

}
项目:AndroidProgramming3e    文件:PhotoGalleryFragment.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    new FetchItemsTask().execute();

    Handler responseHandler = new Handler();
    mThumbnailDownloader = new ThumbnailDownloader<>(responseHandler);
    mThumbnailDownloader.setThumbnailDownloadListener(
        new ThumbnailDownloader.ThumbnailDownloadListener<PhotoHolder>() {
            @Override
            public void onThumbnailDownloaded(PhotoHolder photoHolder, Bitmap bitmap) {
                Drawable drawable = new BitmapDrawable(getResources(), bitmap);
                photoHolder.bindDrawable(drawable);
            }
        }
    );
    mThumbnailDownloader.start();
    mThumbnailDownloader.getLooper();
    Log.i(TAG, "Background thread started");
}
项目:Hands-On-Android-UI-Development    文件:ColorizedCardView.java   
private Bitmap renderDrawable(final Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    final Rect bounds = drawable.getBounds();
    final Bitmap bitmap = Bitmap.createBitmap(
            bounds.width(),
            bounds.height(),
            Bitmap.Config.ARGB_8888
    );

    final Canvas canvas = new Canvas(bitmap);
    canvas.translate(-bounds.left, -bounds.top);
    drawable.draw(canvas);

    return bitmap;
}
项目:HeadlineNews    文件:SpanUtils.java   
private Bitmap drawable2Bitmap(final Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }
    Bitmap bitmap;
    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1,
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    }
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
项目:CXJPadProject    文件:SurroundTestFragment.java   
@OnClick({R.id.start, R.id.red_line, R.id.gray_line})
public void onViewClicked(View view) {
    switch (view.getId()) {
        case R.id.start:
            Bitmap bp = pint1.createSnapshoot();
            Drawable dw = new BitmapDrawable(getResources(),bp);
            im.setImageDrawable(dw);

            break;
        case R.id.red_line:
            break;
        case R.id.gray_line:

            break;
    }
}
项目:LJFramework    文件:ImageUtils.java   
/**
 * drawable转bitmap
 *
 * @param drawable drawable对象
 * @return bitmap
 */
public static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    } else if (drawable instanceof NinePatchDrawable) {
        Bitmap bitmap = Bitmap
                .createBitmap(drawable.getIntrinsicWidth(), drawable
                                .getIntrinsicHeight(),
                        drawable.getOpacity() != PixelFormat.OPAQUE
                        ? Bitmap.Config.ARGB_8888
                        : Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable
                .getIntrinsicHeight());
        drawable.draw(canvas);
        return bitmap;
    } else {
        return null;
    }
}
项目:chips-input-layout    文件:LetterTileProvider.java   
/**
 * Creates a Bitmap object from a Drawable object.
 */
private static Bitmap drawableToBitmap(Drawable dr) {
    // Attempt to retrieve any existing Bitmap, if possible
    if (dr instanceof BitmapDrawable) {
        BitmapDrawable bDr = (BitmapDrawable)dr;
        if (bDr.getBitmap() != null) {
            return bDr.getBitmap();
        }
    }

    // Create a valid blank Bitmap
    final Bitmap bitmap;
    if (dr.getIntrinsicWidth() <= 0 || dr.getIntrinsicHeight() <= 0) {
        // Single color bitmap will be create of 1x1 pixel
        bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    } else {
        bitmap = Bitmap.createBitmap(dr.getIntrinsicWidth(),
                dr.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    }

    // Use our Canvas to draw the Drawable onto the Bitmap
    Canvas canvas = new Canvas(bitmap);
    dr.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    dr.draw(canvas);
    return bitmap;
}
项目:PictureShow    文件:PicPopupWindow.java   
private PicPopupWindow(Context context) {
    mContext = context;
    mInflater = (LayoutInflater) mContext
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mPopupContent = (ViewGroup) mInflater.inflate(
            R.layout.popup_window_list, null);
    mPopupItemContent = (ViewGroup) mPopupContent
            .findViewById(R.id.popup_window_item_content);
    title = (TextView) mPopupContent
            .findViewById(R.id.popup_window_title_text);
    mPopupWindow = new PopupWindow(mPopupContent,
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    mPopupWindow.setFocusable(true);
    mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
    mPopupWindow.setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss() {
            // TODO Auto-generated method stub
            resetItemByTag(setTag);
            if (mAnimationListener != null) {
                mAnimationListener.doAnimation(false);
            }
        }
    });
    mPopupWindow.setAnimationStyle(R.style.popup_window_animation);
}
项目:letv    文件:BlurUtils.java   
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void blurAdvanced(Context context, Bitmap bkg, View view) {
    if (bkg != null) {
        Bitmap overlay = Bitmap.createBitmap(bkg.getWidth(), bkg.getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(overlay);
        Paint paint = new Paint();
        paint.setFlags(2);
        canvas.drawBitmap(bkg, 0.0f, 0.0f, paint);
        overlay = FastBlur.doBlur(overlay, (int) 12.0f, true);
        if (LetvUtils.getSDKVersion() >= 16) {
            view.setBackground(new BitmapDrawable(context.getResources(), overlay));
        } else {
            view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), overlay));
        }
    }
}
项目:okwallet    文件:BitmapFragment.java   
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Bundle args = getArguments();
    final BitmapDrawable bitmap = new BitmapDrawable(getResources(), (Bitmap) args.getParcelable(KEY_BITMAP));
    bitmap.setFilterBitmap(false);

    final Dialog dialog = new Dialog(activity);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.bitmap_dialog);
    dialog.setCanceledOnTouchOutside(true);

    final ImageView imageView = (ImageView) dialog.findViewById(R.id.bitmap_dialog_image);
    imageView.setImageDrawable(bitmap);
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            dismiss();
        }
    });

    return dialog;
}
项目:YiZhi    文件:PersonalPopupWindow.java   
public PersonalPopupWindow(Context context) {
    super(null, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
    mContext = context;
    //设置点击空白处消失
    setTouchable(true);
    setOutsideTouchable(true);
    setClippingEnabled(false);

    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    int w = wm.getDefaultDisplay().getWidth();
    int h = wm.getDefaultDisplay().getHeight();
    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    bitmap.eraseColor(Color.parseColor("#88000000"));//填充颜色
    setBackgroundDrawable(new BitmapDrawable(context.getResources(), bitmap));

    initView();
}
项目:DaiGo    文件:PlaneDrawable.java   
private void getBitmaps(Context context) {
    BitmapDrawable drawable1 = (BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading01);
    drawableMinddleWidth = drawable1.getMinimumWidth() / 2;
    bitmaps.add(drawable1.getBitmap());
    bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading02)).getBitmap());
    bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading03)).getBitmap());
    bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading04)).getBitmap());
    bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading05)).getBitmap());
    bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading06)).getBitmap());
    bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading07)).getBitmap());
    bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading08)).getBitmap());
    bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading09)).getBitmap());
    bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading10)).getBitmap());
    bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading11)).getBitmap());
    bitmaps.add(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.bga_refresh_loading12)).getBitmap());
}
项目:SuperSelector    文件:ImageWorker.java   
/**
         * Once the image is processed, associates it to the imageView
         */
        @Override
        protected void onPostExecute(BitmapDrawable value) {
            //BEGIN_INCLUDE(complete_background_work)
            // if cancel was called on this task or the "exit early" flag is set then we're done
            if (isCancelled() || mExitTasksEarly) {
                value = null;
            }

            final ImageView imageView = getAttachedImageView();
            if (value != null && imageView != null) {
//                if (BuildConfig.DEBUG) {
//                    Log.d(TAG, "onPostExecute - setting bitmap");
//                }
                setImageDrawable(imageView, value);
            }
            //END_INCLUDE(complete_background_work)
        }
项目:PXLSRT    文件:ResultActivity.java   
private void processSavePicture(String directory) {
    File file = new File(new StringBuilder()
            .append(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES))
            .append(File.separator)
            .append(directory)
            .append(File.separator)
            .append(RESULT_FNAME_PREFIX)
            .append(System.currentTimeMillis())
            .append(PrefUtils.getImageFormatPref(getApplicationContext()))
            .toString());
    if (!file.getParentFile().exists()) {
        file.mkdirs();
    }
    try {
        presenter.saveResultPicture(new FileOutputStream(file),
                ((BitmapDrawable) ivResult.getDrawable()).getBitmap(),
                PrefUtils.getImageQualityPref(getApplicationContext()));
        presenter.setPath(file.getAbsolutePath());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:GitHub    文件:BoxingFrescoLoader.java   
private Drawable createDrawableFromFetchedResult(Context context, CloseableImage image) {
    if (image instanceof CloseableStaticBitmap) {
        CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image;
        BitmapDrawable bitmapDrawable = createBitmapDrawable(context, closeableStaticBitmap.getUnderlyingBitmap());
        return (closeableStaticBitmap.getRotationAngle() != 0 && closeableStaticBitmap.getRotationAngle() != -1 ? new OrientedDrawable(bitmapDrawable, closeableStaticBitmap.getRotationAngle()) : bitmapDrawable);
    } else if (image instanceof CloseableAnimatedImage) {
        AnimatedDrawableFactory animatedDrawableFactory = Fresco.getImagePipelineFactory().getAnimatedFactory().getAnimatedDrawableFactory(context);
        if (animatedDrawableFactory != null) {
            AnimatedDrawable animatedDrawable = (AnimatedDrawable) animatedDrawableFactory.create(image);
            if (animatedDrawable != null) {
                return animatedDrawable;
            }
        }
    }
    throw new UnsupportedOperationException("Unrecognized image class: " + image);
}
项目:ColorPickerView    文件:MultiColorPickerView.java   
private int getColorFromBitmap(float x, float y) {
    if (paletteDrawable == null) return 0;

    Matrix invertMatrix = new Matrix();
    palette.getImageMatrix().invert(invertMatrix);

    float[] mappedPoints = new float[]{x, y};
    invertMatrix.mapPoints(mappedPoints);

    if (palette.getDrawable() != null && palette.getDrawable() instanceof BitmapDrawable &&
            mappedPoints[0] > 0 && mappedPoints[1] > 0 &&
            mappedPoints[0] < palette.getDrawable().getIntrinsicWidth() && mappedPoints[1] < palette.getDrawable().getIntrinsicHeight()) {

        invalidate();
        return ((BitmapDrawable) palette.getDrawable()).getBitmap().getPixel((int) mappedPoints[0], (int) mappedPoints[1]);
    }
    return 0;
}
项目:BBSSDK-for-Android    文件:RichEditor.java   
private Bitmap toBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    int width = drawable.getIntrinsicWidth();
    width = width > 0 ? width : 1;
    int height = drawable.getIntrinsicHeight();
    height = height > 0 ? height : 1;

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}
项目:TripBuyer    文件:CircleImageView.java   
private Bitmap getBitmapFromDrawable(Drawable drawable) {
    if (drawable == null) {
        return null;
    }

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    try {
        Bitmap bitmap;

        if (drawable instanceof ColorDrawable) {
            bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
        } else {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
        }

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;
    } catch (OutOfMemoryError e) {
        return null;
    }
}
项目:MusicX-music-player    文件:DrawableUtils.java   
public static Bitmap drawableToBitmap(@NonNull Drawable drawable) {
    Bitmap bitmap;
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }

    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565); // Single color bitmap will be created of 1x1 pixel
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.RGB_565);
    }

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
项目:content-farm-blocker-android    文件:Util.java   
public static Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    final int width = !drawable.getBounds().isEmpty() ? drawable
            .getBounds().width() : drawable.getIntrinsicWidth();

    final int height = !drawable.getBounds().isEmpty() ? drawable
            .getBounds().height() : drawable.getIntrinsicHeight();

    final Bitmap bitmap = Bitmap.createBitmap(width <= 0 ? 1 : width,
            height <= 0 ? 1 : height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}
项目:markor    文件:ContextUtils.java   
public Bitmap getBitmapFromDrawable(int drawableId) {
    Bitmap bitmap = null;
    Drawable drawable = ContextCompat.getDrawable(_context, drawableId);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && (drawable instanceof VectorDrawable || drawable instanceof VectorDrawableCompat)) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            drawable = (DrawableCompat.wrap(drawable)).mutate();
        }

        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
    } else if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    }
    return bitmap;
}
项目:yyox    文件:CircleImageView.java   
private Bitmap getBitmapFromDrawable(Drawable drawable) {
    if (drawable == null) {
        return null;
    }

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    try {
        Bitmap bitmap;

        if (drawable instanceof ColorDrawable) {
            bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
        } else {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
        }

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;
    } catch (OutOfMemoryError e) {
        return null;
    }
}
项目:MultipleItemPage    文件:CircleImageView.java   
private Bitmap getBitmapFromDrawable(Drawable drawable) {
    if (drawable == null) {
        return null;
    }

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    try {
        Bitmap bitmap;

        if (drawable instanceof ColorDrawable) {
            bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
        } else {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
        }

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;
    } catch (OutOfMemoryError e) {
        return null;
    }
}
项目:ImitateZHRB    文件:ACache.java   
@SuppressWarnings("deprecation")
private static Drawable bitmap2Drawable(Bitmap bm) {
    if (bm == null) {
        return null;
    }
    return new BitmapDrawable(bm);
}
项目:Android-UtilCode    文件:SpannableStringUtils.java   
CustomImageSpan(Context context, Bitmap b, int verticalAlignment) {
    super(verticalAlignment);
    mContext = context;
    mDrawable = context != null
            ? new BitmapDrawable(context.getResources(), b)
            : new BitmapDrawable(b);
    int width = mDrawable.getIntrinsicWidth();
    int height = mDrawable.getIntrinsicHeight();
    mDrawable.setBounds(0, 0, width > 0 ? width : 0, height > 0 ? height : 0);
}
项目:LifeHelper    文件:UtilTools.java   
public static void putImageToShare(Context context, ImageView imageView) {
    BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView.getDrawable();
    Bitmap bitmap = bitmapDrawable.getBitmap();
    //第一步:将Bitmap压缩成字节数组输出流
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 80, byteArrayOutputStream);
    //第二步:利用base64将字节数组输出流转换成String
    byte[] byteArray = byteArrayOutputStream.toByteArray();
    String imageString = new String(Base64.encode(byteArray, Base64.DEFAULT));
    //第三步:将String保存到ShareUtils
    ShareUtil.putString(context, StaticClass.IMAGE_TITLE, imageString);
}
项目:amap    文件:MIP_BitmapUtils.java   
/**
 * 缩放Drawable
 * 
 * @author 2013-10-12 下午3:56:40
 * @param drawable
 * @param w
 * @param h
 * @return Drawable
 */
public static Drawable zoomDrawable(Drawable drawable, int w, int h)
{
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    Bitmap oldbmp = drawableToBitmap(drawable); // drawable转换成bitmap
    Matrix matrix = new Matrix(); // 创建操作图片用的Matrix对象
    float scaleWidth = ((float)w / width); // 计算缩放比例
    float scaleHeight = ((float)h / height);
    matrix.postScale(scaleWidth, scaleHeight); // 设置缩放比例
    Bitmap newbmp = Bitmap.createBitmap(oldbmp, 0, 0, width, height, matrix, true); // 建立新的bitmap,其内容是对原bitmap的缩放后的图
    return new BitmapDrawable(newbmp); // 把bitmap转换成drawable并返回
}
项目:letv    文件:BlurUtils.java   
public static void star_blur(Context context, Bitmap bm, ImageView iv) {
    long t1 = System.currentTimeMillis();
    Bitmap overlay = Bitmap.createBitmap((int) (((float) iv.getMeasuredWidth()) / 6.0f), (int) (((float) iv.getMeasuredHeight()) / 6.0f), Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.translate(((float) (-iv.getLeft())) / 6.0f, ((float) (-iv.getTop())) / 6.0f);
    canvas.scale(1.0f / 6.0f, 1.0f / 6.0f);
    Paint paint = new Paint();
    paint.setFlags(2);
    canvas.drawBitmap(bm, 0.0f, 0.0f, paint);
    ImageView imageView = iv;
    imageView.setImageDrawable(new BitmapDrawable(context.getResources(), FastBlur.doBlur(overlay, (int) 5.0f, true)));
    LogInfo.log("clf", "模糊处理时间 t=" + (System.currentTimeMillis() - t1));
}
项目:PictureProgressBar    文件:PictureProgressBar.java   
public void setBarDrawableId(int id) throws Exception {
    Drawable drawable = getResources().getDrawable(id);
    if (drawable instanceof BitmapDrawable) {
        barDrawable = (BitmapDrawable) drawable;
        updateDrawableBounds(progressHeight);
    }else {
        throw new Exception("输入的id不是BitmapDrawable的id");
    }
}
项目:Accessibility    文件:BitmapUtils.java   
public static Bitmap drawableToBitamp(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = ((BitmapDrawable) drawable);
        return bitmapDrawable.getBitmap();
    } else {
        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Config.ARGB_8888 : Config.RGB_565);

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        drawable.draw(canvas);
        return bitmap;
    }
}
项目:garras    文件:CircleImageView.java   
private Bitmap getBitmapFromDrawable(Drawable drawable) {
    if (drawable == null) {
        return null;
    }

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    try {
        Bitmap bitmap;

        if (drawable instanceof ColorDrawable) {
            bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
        } else {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
        }

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
项目:FastAndroid    文件:CircleImageView.java   
private Bitmap getBitmapFromDrawable(Drawable drawable) {
    if (drawable == null) {
        return null;
    }

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    try {
        Bitmap bitmap;

        if (drawable instanceof ColorDrawable) {
            bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
        } else {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
        }

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
项目:android-apkbox    文件:ApkActivityModifier.java   
private static void applyTaskDescription(Activity target, ApkLoaded loaded) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Intent intent = target.getIntent();
        if (intent != null && target.isTaskRoot()) {
            String label = "" + loaded.getApkName();
            Bitmap icon = null;
            Drawable drawable = loaded.getApkIcon();
            if (drawable instanceof BitmapDrawable) {
                icon = ((BitmapDrawable) drawable).getBitmap();
            }
            target.setTaskDescription(new ActivityManager.TaskDescription(label, icon));
        }
    }
}
项目:cafebar    文件:CafeBarUtil.java   
@Nullable
static Drawable toDrawable(@NonNull Context context, @Nullable Bitmap bitmap) {
    try {
        if (bitmap == null) return null;
        return new BitmapDrawable(context.getResources(), bitmap);
    } catch (OutOfMemoryError e) {
        return null;
    }
}