I'm new to using Bitmaps and don't completely understand why I'm running out of memory. I want to save an image of which the path is passed back to an activity from the camera app like so:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
adapter.saveResizedImage(mCurrentPhotoPath);
}
}
Calling the adapter method:
public void saveResizedImage(String path){
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap photo = (Bitmap) BitmapFactory.decodeFile(path, bmOptions);
photo = Bitmap.createScaledBitmap(photo, INSTAGRAM_FORMAT_H, INSTAGRAM_FORMAT_W, false);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
File f = new File(path);
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
TernaryActivity.mCurrentPhotoPath = f.getAbsolutePath();
} catch (IOException e) {
e.printStackTrace();
}
}
Exception occurs at Bitmap photo = (Bitmap) BitmapFactory.decodeFile(path, bmOptions);
I should mention that the activity which calls onActivityResult()
can contain up to 6 images and that the error occurs when I took the 5th picture and it was passed back to the activity.