public static boolean appendScaledDownImageToStream(String sourcePath, OutputStream outputStream) {
int imageOrientation = 0;
try {
ExifInterface exif = new ExifInterface(sourcePath);
imageOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
} catch (IOException e) {
logException(e);
}
CountingOutputStream cos = null;
try {
cos = new CountingOutputStream(new BufferedOutputStream(outputStream));
System.gc();
Bitmap smaller = ImageUtil.createScaledBitmapFromLocalImageSource(sourcePath, MAX_SENT_IMAGE_EDGE, MAX_SENT_IMAGE_EDGE, null, imageOrientation);
smaller.compress(Bitmap.CompressFormat.JPEG, 95, cos);
cos.flush();
ApptentiveLog.v(UTIL, "Bitmap bytes appended, size = " + (cos.getBytesWritten() / 1024) + "k");
smaller.recycle();
return true;
} catch (Exception e) {
ApptentiveLog.a(UTIL, e, "Error storing image.");
logException(e);
return false;
} finally {
Util.ensureClosed(cos);
}
}