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


当前回答

如果你有一个位图图像,你想用它来绘图,比如

Bitmap contact_pic;    //a picture to show in drawable
drawable = new BitmapDrawable(contact_pic); 

其他回答

尝试一下,它将位图类型的图像转换为可绘制

Drawable d = new BitmapDrawable(getResources(), bitmap);

隐蔽位映射绘制在草图应用程序使用代码

    android.graphics.drawable.BitmapDrawable d = new android.graphics.drawable.BitmapDrawable(getResources(), bitmap);

如果你有一个位图图像,你想用它来绘图,比如

Bitmap contact_pic;    //a picture to show in drawable
drawable = new BitmapDrawable(contact_pic); 

只要这样做:

private void setImg(ImageView mImageView, Bitmap bitmap) {

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

对于Kotlin用户:

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

Bitmap.toDrawable(资源)