Android 获取Bitmap方式

1、获得当前项目资源文件(assets)下图片

    (1).获得图片数据流

   private Bitmap getBotMapInfo() {
Bitmap bitmap = null;
try {
InputStream is = mContext.getAssets().open("picture/ic_northeasttycoon.png");
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
(2) 绑定需要的图片
mIv_north_back.setImageBitmap(getBotMapInfo());  // mIv_north_back 页面图片ID
2、 获得安装到android设备的目录进行绑定
(1)、获得当前设备放图片目录
String path= Environment.getExternalStorageDirectory()+ File.separator+"ic_northeasttycoon.png";
Bitmap bm = BitmapFactory.decodeFile(path);
(2)、绑定图片
mIv_north_back.setImageBitmap(bm);

猜你喜欢

转载自www.cnblogs.com/northeastTycoon/p/11418928.html