我在 SD 卡
中有一张图片我想从 SD 卡
中获取图片并在 ImageView
中设置。请大家帮帮我已尝试以下代码。
我的代码:
sendImageFromFolder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri uri=null;
ArrayList<Uri> arrayList=new ArrayList<Uri>();
ImageView imageView= (ImageView) findViewById(R.id.imageView);
File pictues= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String[] listOfPictures=pictues.list();
for(String s:listOfPictures){
uri=Uri.parse("file://"+ pictues.toString() +"/"+s);
arrayList.add(uri);
}
InputStream inputStream = null;
FileOutputStream fileOutputStream=null;
Bitmap bmp;
try {
inputStream = getContentResolver().openInputStream(arrayList.get(0));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
bmp = BitmapFactory.decodeStream(bufferedInputStream);
imageView.setImageBitmap(bmp);
}
最佳答案
File pictureFile = new File("Path to your image");
Bitmap bitmap = BitmapFactory.decodeFile(pictureFile.getAbsolutePath());
mImage.setImage(bitmap);
关于android - 将SD卡图像设置为ImageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38114785/