This is how I do it now, and it consumes a lot of memory. User will select an image from gallery and image path is passed to cropper object which does all those things below:
BitmapFactory.Options bOptions = new BitmapFactory.Options();
bOptions.inScaled = false;
rawBitmap = BitmapFactory.decodeFile(imageFilePath, bOptions);
// Create rotated bitmap since image can be rotated - matrix is passed
rotatedBitmap = Bitmap.createBitmap(rawBitmap,
0, 0, rawBitmap.getWidth(), rawBitmap.getHeight(), matrix, true);
rawBitmap.recycle();
// Crop bitmap
croppedBitmap = Bitmap.createBitmap(rotatedBitmap,
cropStartX, cropStartY, cropWidth, cropHeight, null, true);
rotatedBitmap.recycle();
FileOutputStream out = new FileOutputStream(pictureFile);
croppedBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
croppedImagePath = pictureFile.getAbsolutePath();
croppedBitmap.recycle();
0 comments:
Post a Comment