2014-02-15 46 views
0

我使用以下片段(來自SO帖子here),將使用相機拍攝的照片作爲縮略圖顯示在imagevew中。但圖片的縮略圖不顯示並保持空白。可能是什麼原因?設置使用相機拍攝的照片,作爲圖像視圖中的縮略圖

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); 
} 
+0

嘿,看到我更新的答案。 –

回答

1
bmOptions.inJustDecodeBounds = true; 

將導致返回任何實際的位圖。它旨在讀取有關位圖的信息(如寬度/高度),而不實際將所有內容都加載到內存中。

- >inJustDecodeBounds

我建議檢查出有關顯示位圖此鏈接到官方Android SDK文檔: Link

1

就出在這裏你的問題...

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

這裏,你正在通過圖片而不是通過imageBitmap這是你的tak圖片。所以,你正確的代碼將是...

Bitmap bitmap = Bitmap.createScaledBitmap(imageBitmap, targetW, targetH, true); 
+0

謝謝你的幫助,但是很抱歉,這是我發佈問題時的錯誤。 createScaledBitmap是另一種我傳遞imageBitmap的方法,它在該方法中用作圖片。請看我現在的編輯 – user264953

+0

我認爲你不明白我指出的問題。請仔細閱讀我的答案。 –

相關問題