public static boolean appendScaledDownImageToStream(String sourcePath, OutputStream outputStream) { // Retrieve image orientation int imageOrientation = 0; try { ExifInterface exif = new ExifInterface(sourcePath); imageOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); } catch (IOException e) { logException(e); } // Copy the file contents over. 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); } }
cos = new CountingOutputStream(bos); byte[] buf = new byte[2048]; int count; while ((count = is.read(buf, 0, 2048)) != -1) { cos.write(buf, 0, count); ApptentiveLog.v(UTIL, "File saved, size = " + (cos.getBytesWritten() / 1024) + "k"); } catch (IOException e) { ApptentiveLog.e(UTIL, "Error creating local copy of file attachment.");
cos = new CountingOutputStream(new BufferedOutputStream(new FileOutputStream(localFile))); System.gc(); Bitmap smaller = ImageUtil.createScaledBitmapFromLocalImageSource(sourcePath, MAX_SENT_IMAGE_EDGE, MAX_SENT_IMAGE_EDGE, null, imageOrientation); cos.flush(); ApptentiveLog.v(UTIL, "Bitmap saved, size = " + (cos.getBytesWritten() / 1024) + "k"); smaller.recycle(); System.gc();