code: 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;
      }
docs: Compress the image at with the specified path and return the bitmap data of the compressed image.
  
  @param imagePath         The path of the image file you wish to compress.
  @param deleteSourceImage If True will delete the source file
  @return Compress image bitmap
  @throws IOException