Util.java 文件源码

java
阅读 34 收藏 0 点赞 0 评论 0

项目:content-farm-blocker-android 作者:
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;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号