2013-08-19 103 views
0

選擇的圖像的縮略圖我想這個代碼片段:獲取從畫廊

if (resultCode == RESULT_OK) { 
     if (requestCode == REQUEST_CAMERA) { 
      photoUri = capturedImagePath(); 
      Log.d("path to captured image", capturedImagePath().toString()); 
      Bitmap aBitmap = BitmapFactory.decodeFile(photoUri.toString()); 
      mProfilePic.setImageBitmap(aBitmap); 
      mEncodedImageString = convertBitmapToString(aBitmap); 
     Log.v("Base64 Image String : ", mEncodedImageString); 

    } else if (requestCode == SELECT_FILE) { 
     photoUri = data.getData(); 
     String[] filePathColumn = { 
      MediaStore.Images.Media.DATA 
     }; 
     Cursor cursor = getContentResolver().query(photoUri, filePathColumn, null, null, 
       null); 
     cursor.moveToFirst(); 
     int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
     String picturePath = cursor.getString(columnIndex); 
     cursor.close(); 
     Bitmap aBitmap = BitmapFactory.decodeFile(picturePath); 
     mProfilePic.setImageBitmap(aBitmap); 
     mEncodedImageString = convertBitmapToString(aBitmap); 
     Log.v("Base64 Image String : ", mEncodedImageString); 
    } 
} 

得到圖片的路徑,但它給了我的原始圖像。我想要的是所選圖像的縮略圖。任何人都可以請幫我實現一樣嗎?

+0

這些圖像是否有縮略圖?如果沒有,那麼你將需要創建它們。 – andy256

回答

1

您可以輕鬆地創建這樣一個縮略圖:

int thumbFactor = 4; // choose a power of 2 
Bitmap thumb = Bitmap.createScaledBitmap(image, image.getWidth()/thumbFactor, image.getHeight()/thumbFactor, false); 

Bitmap

1

其實你無法通過URI查詢得到的縮略圖。因爲Gallery自己緩存縮略圖。如果你需要縮略圖,你必須自己解碼原始圖像。