2013-08-19 107 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自己缓存缩略图。如果你需要缩略图,你必须自己解码原始图像。