0

I use the following snippet(from SO post here) to display photo taken using camera as a thumbnail, in an imagevew. But the thumbnail of the picture does not show up and remain blank. What can be the reason?

    Bundle extras = data.getExtras();
                if(extras.get("data") != null){
                    Bitmap imageBitmap = (Bitmap) extras.get("data");
   // Get the dimensions of the View
    int targetW = imgViewPreview.getWidth();
    int targetH = imgViewPreview.getHeight();

    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    Bitmap bitmap = Bitmap.createScaledBitmap(picture, targetW, targetH, true);
    imgViewPreview.setVisibility(View.VISIBLE);
    imgViewPreview.setImageBitmap(imageBitmap);
}
Community
  • 1
  • 1
user264953
  • 1,837
  • 8
  • 37
  • 63

2 Answers2

1
bmOptions.inJustDecodeBounds = true;

will cause no actual Bitmap to be returned. It is intended to read information about the bitmap (such as width/height) without actually loading everything into memory at this time.

--> inJustDecodeBounds

i recommended checking out this link to the official Android SDK documentation about displaying bitmaps: Link

cania
  • 857
  • 10
  • 16
1

Here lies your problem...

Bitmap bitmap = Bitmap.createScaledBitmap(picture, targetW, targetH, true);

Here, you are passing picture instead of passing imageBitmap which is your taken picture. So, you correct code will be...

Bitmap bitmap = Bitmap.createScaledBitmap(imageBitmap, targetW, targetH, true);
Hamid Shatu
  • 9,664
  • 4
  • 30
  • 41
  • thankyou for the help, but sorry..it was my mistake while posting the question. The createScaledBitmap was in another method to which i was passing imageBitmap and it was taken in that method as picture. Please see my edit now – user264953 Feb 15 '14 at 10:13
  • I think you didn't understand what I'm pointing for the problem. Please, read my answer carefully. – Hamid Shatu Feb 15 '14 at 10:25