如何将位图图像转换为可绘制?


当前回答

这是另一个:

Drawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);

其他回答

1)位图到可绘制:

Drawable mDrawable = new BitmapDrawable(getResources(), bitmap);
// mImageView.setDrawable(mDrawable);

2)可绘制位图:

Bitmap mIcon = BitmapFactory.decodeResource(context.getResources(),R.drawable.icon_resource);
// mImageView.setImageBitmap(mIcon);

我使用了上下文

//Convert bitmap to drawable
Drawable drawable = new BitmapDrawable(context.getResources(), bitmap);

官方位图绘制文档

这是一个关于如何将位图转换为可绘制的示例

Bitmap bitmap;  
//Convert bitmap to drawable
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
imageView.setImageDrawable(drawable);

这是另一个:

Drawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);

对于Kotlin用户:

Kotlin有一个转换Bitmap到BitmapDrawable的函数:

Bitmap.toDrawable(资源)