0

I'm trying to display a captured image from a camera intent, but when I call a showPhoto method the image isn't shown in the ImageView. There is no error output to the stack trace so I'm not sure how the issue can be debugged.

Does anyone know what is wrong with the method that its not showing the captured image?

The showPhoto method is as follows:

private void showPhoto(Uri photoUri) {
          String filePath = photoUri.getEncodedPath();
          File imageFile = new File(filePath);
          //File imageFile = new File(photoUri.getPath());
          if (imageFile.exists()){
             Drawable oldDrawable = photoImage.getDrawable(); 
             if (oldDrawable != null) { 
                 ((BitmapDrawable)oldDrawable).getBitmap().recycle();
            }
             Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
             BitmapDrawable drawable = new BitmapDrawable(this.getResources(), bitmap);
             photoImage.setScaleType(ImageView.ScaleType.FIT_CENTER);
             photoImage.setImageDrawable(drawable);
          }       
        }

This is the tutorial that I've followed: http://www.linux.com/learn/tutorials/722038-android-calling-the-camera

The device I'm testing on is JellyBean 4.1 and this is the link to the complete class:

http://hastebin.com/oqokupulol.java

Brian Var
  • 6,029
  • 25
  • 114
  • 212

1 Answers1

1

Use BitmapOptions.inJustDecodeBounds to find out the dimension of the image first

Typically, Android won't load images larger than 4000px wide/tall

If you find out the image is too large, you can use BitmapOptions.inSampleSize to downscale the image so that Android would load it

And in fact, you can directly use ImageView.setImageBitmap(Bitmap) instead of setImageDrawable

Patrick Chan
  • 1,019
  • 10
  • 14