Uri selectedImageUri = data.getData();
String[] fileProperties = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImageUri, fileProperties, null, null, null);
cursor.moveToFirst();
int filePathIndex = cursor.getColumnIndex(fileProperties[0]);
String selectedImagePath = cursor.getString(filePathIndex);
String imageDec = decodeFile(selectedImagePath , 200 , 200);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(selectedImagePath, options);
options.inSampleSize = CommonUtils.calculateInSampleSize(options, 200,
200);
options.inJustDecodeBounds = false;
Bitmap profileImageBitmap = BitmapFactory.decodeFile(selectedImagePath, options);
//Resize method
public Bitmap getResizedBitmap(Bitmap image, int maxSize) {
int width = image.getWidth();
int height = image.getHeight();
float bitmapRatio = (float)width / (float) height;
if (bitmapRatio > 1) {
width = maxSize;
height = (int) (width / bitmapRatio);
} else {
height = maxSize;
width = (int) (height * bitmapRatio);
}
return Bitmap.createScaledBitmap(image, width, height, true);
}
No comments:
Post a Comment