public Bitmap getCompressBitmap ( String imagePath , boolean deleteSourceImage ) throws IOException { File imageFile = new File ( compressImage ( imagePath , new File ( Environment . getExternalStoragePublicDirectory ( Environment . DIRECTORY_PICTURES ) , "Silicompressor/images" ) ) ) ; Uri newImageUri = FileProvider . getUriForFile ( mContext , FILE_PROVIDER_AUTHORITY , imageFile ) ; Bitmap bitmap = MediaStore . Images . Media . getBitmap ( mContext . getContentResolver ( ) , newImageUri ) ; if ( deleteSourceImage ) { boolean isdeleted = deleteImageFile ( imagePath ) ; Log . d ( LOG_TAG , ( isdeleted ) ? "Source image file deleted" : "Error: Source image file not deleted." ) ; } // Delete the file created during the image compression deleteImageFile ( imageFile . getAbsolutePath ( ) ) ; // Return the required bitmap return bitmap ; }
Compress the image at with the specified path and return the bitmap data of the compressed image .