How to set an image in an image view, android
Hi I want to show an image from SD card. I have 10 images. out of which i am able to show 9 images but 1 image i cannot show in image view.
My SD card location is correct. I am using android programming. I am getting file exists as true. also I am getting not null input stream but when I want to get Drawable object for some fiels i am not getting but for all others getting drawable object.
Also I have tried using
iv1.setImageUR开发者_StackOverflow社区I(Uri.parse(str1))
but i didnot get any solution
Following is my code snippet
InputStream is1 = getBitMapImage(str1);
InputStream is2 = getBitMapImage(str2);
InputStream is3 = getBitMapImage(str3);
Drawable d1 = Drawable.createFromStream(is1, "first");
Drawable d2 = Drawable.createFromStream(is2, "second");
Drawable d3 = Drawable.createFromStream(is3, "third");
iv1.setImageDrawable(d1);
iv2.setImageDrawable(d2);
iv3.setImageDrawable(d3);
System.out.println(is1+"....d1...."+d1);
System.out.println(is2+"....d2...."+d2);
System.out.println(is3+"....d3...."+d3);
public static BufferedInputStream getBitMapImage(String filePath) {
Log.e("Utilities", "Original path of image from Utilities "+filePath);
File imageFile = null;
FileInputStream fileInputStream = null;
BufferedInputStream buf= null;
try{
imageFile= new File(filePath);
System.out.println("Does Images File exist ..."+imageFile.exists());
fileInputStream = new FileInputStream(filePath);
buf = new BufferedInputStream(fileInputStream);
}catch(Exception ex){
}finally{
try{
imageFile = null;
fileInputStream.reset();
fileInputStream.close();
}catch(Exception ex){}
}
return buf;
}
Some image files cannot be shared. Blackbery rem file cannot be shared. That type of file cannot be opened if stored directly. So during storing convert that file into .jpg file and then only u can open those file. For checking purpose pullout your file from the device to your system then convert in into .jpg file using gimp and push into device once again then try to run your program and check whether your image file is diplayed in your image view.
Thanks Sunil
精彩评论