如何将位图图像转换为可绘制?
当前回答
这是另一个:
Drawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);
其他回答
听起来你想要使用BitmapDrawable
从文档中可以看到:
一个包装位图和罐头的Drawable 平铺、拉伸或对齐。你 可以创建一个BitmapDrawable 文件路径,一个输入流,通过 XML膨胀,或从位图 对象。
对于Kotlin用户:
Kotlin有一个转换Bitmap到BitmapDrawable的函数:
Bitmap.toDrawable(资源)
这是另一个:
Drawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);
只要这样做:
private void setImg(ImageView mImageView, Bitmap bitmap) {
Drawable mDrawable = new BitmapDrawable(getResources(), bitmap);
mImageView.setDrawable(mDrawable);
}
1)位图到可绘制:
Drawable mDrawable = new BitmapDrawable(getResources(), bitmap);
// mImageView.setDrawable(mDrawable);
2)可绘制位图:
Bitmap mIcon = BitmapFactory.decodeResource(context.getResources(),R.drawable.icon_resource);
// mImageView.setImageBitmap(mIcon);
推荐文章
- 改变开关的“开”色
- 以编程方式将EditText的输入类型从PASSWORD更改为NORMAL,反之亦然
- 如何在隐藏和查看密码之间切换
- 在Android上调整一个大的位图文件到缩放输出文件
- 如何更改Android版本和代码版本号?
- Android Studio突然无法解析符号
- 应用程序重新启动而不是恢复
- 如何设置整个应用程序在纵向模式?
- Android中文本的阴影效果?
- 以编程方式设置TextView的布局权重
- Android -如何覆盖“后退”按钮,所以它不完成()我的活动?
- 如何从通知点击发送参数到一个活动?
- 导航目标xxx对于这个NavController是未知的
- 使用ConstraintLayout均匀间距的视图
- 文件google-services错误。模块根文件夹中缺少Json。谷歌服务插件没有它就不能正常工作。