xyz rety xyz rety - 5 months ago 31
Android Question

set SD card image to ImageView?

i have an images in SD card i want to take image from SD card and set in the ImageView.please help me guys i have no idea how can i do this.

i tried this:

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


);
}

Answer
 File pictureFile = new File("Path to your image");
 Bitmap bitmap = BitmapFactory.decodeFile(pictureFile.getAbsolutePath());
 mImage.setImage(bitmap);
Comments