private Bitmap drawableToBitmap(Drawable drawable) {
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
Log.i("Wooo", "-drawableToBitmap--" + h + "--w--" + w);
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
drawable.draw(canvas);
int width = bitmap.getWidth(); // 更改 APP 展示图标尺寸
int height = bitmap.getHeight();
int newWidth = 180;
int newHeight = 180;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap newbm = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
return newbm;
}
drawable 转 bitmap 并设置 bm 尺寸
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 标签(空格分隔): android 问题集 由于特殊效果需要,drawable中定义很多layer-list的xm...
- In short Bitmap - is a representation of image in byte fo...
- 在 Android UI 开发中,View 作为其基本元素,必定被大家接触过,而改变 View 图形显示的 2D ...