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


当前回答

只要这样做:

private void setImg(ImageView mImageView, Bitmap bitmap) {

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

其他回答

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

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

只要这样做:

private void setImg(ImageView mImageView, Bitmap bitmap) {

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

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

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

1)位图到可绘制:

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

2)可绘制位图:

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

这是另一个:

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