Far*_*ari 429 android bitmap android-drawable
如何将Bitmap图像转换为Drawable?
小智 807
试试这个它将Bitmap类型图像转换为Drawable
Drawable d = new BitmapDrawable(getResources(), bitmap);
Run Code Online (Sandbox Code Playgroud)
Gra*_*can 258
听起来像你想要使用 BitmapDrawable
从文档:
一个
Drawable包装位图,可以平铺,拉伸或对齐.您可以BitmapDrawable通过文件路径,输入流,XML通胀或Bitmap对象创建.
Zul*_*xia 144
看到转换为a时位图错误缩放的大量问题,转换BitmapDrawable的一般方法应该是:
Drawable d = new BitmapDrawable(getResources(), bitmap);
Run Code Online (Sandbox Code Playgroud)
如果没有Resources reference,则bitmap可能无法正常正确缩放时渲染,甚至.这里有很多问题,只需使用这种方法而不是仅使用bitmap参数的直接调用即可解决.
Cri*_*vez 35
官方Bitmapdrawable 文档
这是关于如何将位图转换为drawable的示例
Bitmap bitmap;
//Convert bitmap to drawable
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
imageView.setImageDrawable(drawable);
Run Code Online (Sandbox Code Playgroud)
Sam*_*van 31
我用上下文
//Convert bitmap to drawable
Drawable drawable = new BitmapDrawable(context.getResources(), bitmap);
Run Code Online (Sandbox Code Playgroud)
Pir*_*hah 20
如果你有一个位图图像,你想在drawable中使用它,比如
Bitmap contact_pic; //a picture to show in drawable
drawable = new BitmapDrawable(contact_pic);
Run Code Online (Sandbox Code Playgroud)
Joo*_*lah 11
这样做:
private void setImg(ImageView mImageView, Bitmap bitmap) {
Drawable mDrawable = new BitmapDrawable(getResources(), bitmap);
mImageView.setDrawable(mDrawable);
}
Run Code Online (Sandbox Code Playgroud)
San*_*inh 10
1) 位图到 Drawable :
Drawable mDrawable = new BitmapDrawable(getResources(), bitmap);
// mImageView.setDrawable(mDrawable);
Run Code Online (Sandbox Code Playgroud)
2)可绘制到位图:
Bitmap mIcon = BitmapFactory.decodeResource(context.getResources(),R.drawable.icon_resource);
// mImageView.setImageBitmap(mIcon);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
335289 次 |
| 最近记录: |