code: private static void save(Bitmap src, String fileName, Bitmap.CompressFormat format, int quality) throws ImageSaveException {
          FileOutputStream outputStream = null;
          try {
              outputStream = new FileOutputStream(fileName);
              src.compress(format, quality, outputStream);
              outputStream.close();
          } catch (IOException e) {
              throw new ImageSaveException(e);
          } finally {
              if (outputStream != null) {
                  try {
                      outputStream.close();
                  } catch (IOException e1) {
                      e1.printStackTrace();
                  }
              }
          }
      }
docs: Saving image to file
  
  @param src      source image
  @param fileName destination file name
  @param format   image format
  @param quality  jpeg quality
  @throws ImageSaveException if it is unable to save image