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


当前回答

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

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

其他回答

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

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

听起来你想要使用BitmapDrawable

从文档中可以看到:

一个包装位图和罐头的Drawable 平铺、拉伸或对齐。你 可以创建一个BitmapDrawable 文件路径,一个输入流,通过 XML膨胀,或从位图 对象。

这是另一个:

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

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

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

我使用了上下文

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