您的位置:首页 > 其它

ImageView显示图像

2010-10-07 00:03 393 查看
ImageView显示图像有多个方法

setImageResource(int resId);

setImageURI(Uri uri);

setImageDrawable(Drawable drawable);

setImageBitmap(Bitmap bm);

对于资源图像,可以直接应用调用资源来显示,但是有时候我们需要对显示的图像先做某种操作,因此需要把资源转换为BitmapDrawable或者Bitmap

1、从资源中获取BitmapDrawble

private BitmapDrawable getDrawableFromId(int id){
Resources res = getResources();
return (BitmapDrawable)res.getDrawable(id);
}


2、从资源中获取Bitmap图像

private Bitmap getBitmapFromId(int id){
Resources res = getResources();
BitmapDrawable bitDraw = new BitmapDrawable(res.openRawResource(R.drawable.lander_firing));
Bitmap bm = bitDraw.getBitmap();
return bm;
//mImageView.setImageBitmap(bm);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: