public static boolean createScaledDownImageCacheFile ( String sourcePath , String cachedFileName ) { File localFile = new File ( cachedFileName ) ; // Retrieve image orientation int imageOrientation = 0 ; try { ExifInterface exif = new ExifInterface ( sourcePath ) ; imageOrientation = exif . getAttributeInt ( ExifInterface . TAG_ORIENTATION , ExifInterface . ORIENTATION_NORMAL ) ; } catch ( IOException e ) { } // Copy the file contents over. CountingOutputStream cos = null ; try { 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 ) ; // TODO: Is JPEG what we want here? smaller . compress ( Bitmap . CompressFormat . JPEG , 95 , cos ) ; cos . flush ( ) ; ApptentiveLog . v ( UTIL , "Bitmap saved, size = " + ( cos . getBytesWritten ( ) / 1024 ) + "k" ) ; smaller . recycle ( ) ; System . gc ( ) ; } catch ( FileNotFoundException e ) { ApptentiveLog . e ( UTIL , e , "File not found while storing image." ) ; logException ( e ) ; return false ; } catch ( Exception e ) { ApptentiveLog . a ( UTIL , e , "Error storing image." ) ; logException ( e ) ; return false ; } finally { Util . ensureClosed ( cos ) ; } return true ; }
This method creates a cached version of the original image and compresses it in the process so it doesn t fill up the disk . Therefore do not use it to store an exact copy of the file in question .