Hi I am unable to resize image using Picasso. I want to resize the image and send it to the server. I have saved the image to my internal directory and I am accessing it using mCurrentPhotoPath. The file gets uploaded to the server but it s not resized. Any help is appreciated.
private File createImageFile() throws IOException {
OutputStream outStream = null;
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
mCurrentPhotoPath = image.getAbsolutePath();
try {
outStream = new FileOutputStream(mCurrentPhotoPath);
Bitmap bitmap = Picasso.get()
.load(mCurrentPhotoPath)
.resize(80, 80).fit()
.centerInside().get();
bitmap = getResizedBitmap(bitmap,20);
bitmap.compress(Bitmap.CompressFormat.PNG, 0, outStream);
outStream.flush();
outStream.close();
// Save a file: path for use with ACTION_VIEW intents
Log.i("file path before", mCurrentPhotoPath);
} catch (Exception e) {
Log.i("exception", e.toString());
}
return image;
}
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);
}
The file size is 3 - 4 MB. I want max 600KB file.