如何将位图图像转换为可绘制?
当前回答
只要这样做:
private void setImg(ImageView mImageView, Bitmap bitmap) {
Drawable mDrawable = new BitmapDrawable(getResources(), bitmap);
mImageView.setDrawable(mDrawable);
}
其他回答
官方位图绘制文档
这是一个关于如何将位图转换为可绘制的示例
Bitmap bitmap;
//Convert bitmap to drawable
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
imageView.setImageDrawable(drawable);
听起来你想要使用BitmapDrawable
从文档中可以看到:
一个包装位图和罐头的Drawable 平铺、拉伸或对齐。你 可以创建一个BitmapDrawable 文件路径,一个输入流,通过 XML膨胀,或从位图 对象。
隐蔽位映射绘制在草图应用程序使用代码
android.graphics.drawable.BitmapDrawable d = new android.graphics.drawable.BitmapDrawable(getResources(), bitmap);
只要这样做:
private void setImg(ImageView mImageView, Bitmap bitmap) {
Drawable mDrawable = new BitmapDrawable(getResources(), bitmap);
mImageView.setDrawable(mDrawable);
}
这是另一个:
Drawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);
推荐文章
- Openssl不被视为内部或外部命令
- 无法执行dex:在Eclipse中超过GC开销限制
- 如何以编程方式将视图添加到视图
- 单击url会打开默认浏览器
- 使用Retrofit刷新OAuth令牌,而不修改所有调用
- 多个dex文件定义了landoid /support/v4/accessibilityservice/AccessibilityServiceInfoCompat
- 如何获得动作栏的高度?
- 从活动外部调用startActivity() ?
- createScaledBitmap的过滤器参数做什么?
- 为什么我在使用adb时访问数据文件夹被拒绝?
- 如何确定Android设备的GPS是否已启用
- 没有找到与给定名称匹配的资源:attr 'android:keyboardNavigationCluster'。更新到支持库26.0.0时
- 禁用在android中打开导航抽屉的滑动手势
- Android:允许平板电脑竖屏和横屏,但强制手机竖屏?
- 如何使布局与视图填充剩余的空间?