ImageView won't show image when set by setImageBitmap()
I am having problems getting an existing image on the sdcard to display.
ImageView _photoView = (ImageView)findViewById(R.id.img_photo);
File photoFile = new File(Environment.getExternalStorageDirectory(), Session.PHOTO_FILE_NAME);
rawFileInputStream = new FileInputStream(photoFile);
Bitmap origPhoto = BitmapFactory.decodeStr开发者_运维知识库eam(rawFileInputStream, null, new BitmapFactory.Options());
_photoView.setImageBitmap(origPhoto);
Log.d(TAG, origPhoto.getWidth() + " - " + origPhoto.getHeight());
The photo does exist and the dimensions show up as displayed, but nothing appears within the ImageView tag
<ImageView
android:id="@+id/img_photo"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
I tried to set the height to a fixed size, but I still can't see the photo.
I've seen a few posts on SO regarding this issue, but none of them have yet been answered.
Any ideas?
** Update If I load the file directly, instead of through a filestream it works
Bitmap origPhoto = BitmapFactory.decodeFile("/mnt/sdcard/" + Session.PHOTO_FILE_NAME);
double scale = MAX_WIDTH * 1.0 / origPhoto.getWidth();
int height = (int)(origPhoto.getHeight() * scale);
Bitmap scaledPhoto = Bitmap.createScaledBitmap(origPhoto, MAX_WIDTH, height, true);
_photoView.setImageBitmap(origPhoto);
but if I then add the Bitmap.createScaledBitmap()
method call it no longer works and the image is not displayed.
I replaced the file streaming with Bitmap scaledPhoto = BitmapFactory.decodeFile("/mnt/sdcard/" + Session.PHOTO_FILE_NAME); and it now works (what was mentioned in the Update)
精彩评论