I am loading an image from Gallery as bitmap - on to a canvas and performing some drawings on it.
At any point in time I have this bitmap containing my drawings, readily available.
I have a requirement to crop this bitmap. For this I need to convert the bitmap first into an image file - since there are no api's or libraries available to crop a bitmap directly. 2-3 seconds, I loose in this conversion process.
Is there a way out(or using any 3rd party library), by which I can directly crop a bitmap, without actually having to convert this into an image file. This will help me a lot in improving the performance of my app.
Any help is much appreciated.
PS: For reference, I have added the bitmap conversion code below. The library I use for cropping currently is - https://github.com/jdamcd/android-crop
drawView.setDrawingCacheEnabled(true);
Date d = new Date();
CharSequence s = DateFormat.format("MM-dd-yy hh-mm-ss", d.getTime());
Bitmap bitmap = drawView.getResultBitmap();
File sdCardDirectory = Environment.getExternalStorageDirectory();
File image = new File(sdCardDirectory, "DCIM/Camera/" + s.toString() + ".png");
boolean success = false;
// Encode the file as a PNG image.
FileOutputStream outStream;
try {
outStream = new FileOutputStream(image);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
/* 100 to keep full quality of the image */
outStream.flush();
outStream.close();
success = true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//static final Uri imgUri;
if (success) {
MediaScannerConnection.scanFile(getActivity(), new String[]{
image.getAbsolutePath()},
null, new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
beginCrop(uri);
}
});