android显示图片
1、从res文件下获取图片资源
ImageView images=(ImageView) findViewById(R.id.imageview1);
InputStream is=this.getResources().openRawResource(R.drawable.test2);
BitmapFactory.Options options=new BitmapFactory.Options();
options.inJustDecodeBounds = false;
options.inSampleSize = 10; //width,hight设为原来的十分一
Bitmap btp =BitmapFactory.decodeStream(is,null,options);
images.setImageBitmap(btp);
2、从SD卡下获取图片资源。
提示:在AndroidManifest.xml中加入权限
ImageView images=(ImageView) findViewById(R.id.imageview1);
String path="/storage/sdcard/images/test2.jpg";
BitmapFactory.Options option = new BitmapFactory.Options();
option.inSampleSize = 4;
Bitmap bm = BitmapFactory.decodeFile(path,option)
获取SD卡根目录:
String path = Environment.getExternalStorageDirectory() + "/"
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-10 13:52:45