我在显示SD卡上的现有图像时遇到问题.
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.decodeStream(rawFileInputStream,null,new BitmapFactory.Options()); _photoView.setImageBitmap(origPhoto); Log.d(TAG,origPhoto.getWidth() + " - " + origPhoto.getHeight());
照片确实存在且尺寸显示为显示,但ImageView标记内没有任何内容
<ImageView android:id="@+id/img_photo" android:layout_width="fill_parent" android:layout_height="wrap_content" />
我试图将高度设置为固定大小,但我仍然看不到照片.
关于这个问题,我在SO上看到了一些帖子,但是还没有人回答过.
有任何想法吗?
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);