code: private static File writeBitmapToDirectory(Bitmap bitmap, String filename, File dirFile) {
          if (!dirFile.exists() && !dirFile.mkdirs()) {
              LogUtils.log(ScreenshotUtils.class, Log.WARN,
                      "Directory %s does not exist and could not be created.",
                      dirFile.getAbsolutePath());
              return null;
          }
  
          final File outFile = new File(dirFile, filename);
          if (outFile.exists()) {
              LogUtils.log(ScreenshotUtils.class, Log.WARN,
                      "Tried to write a bitmap to a file that already exists.");
              return null;
          }
  
          FileOutputStream outStream = null;
          try {
              outStream = new FileOutputStream(outFile);
              final boolean compressSuccess = bitmap.compress(
                      CompressFormat.PNG, 0 /* quality, ignored for PNG */, outStream);
  
              if (compressSuccess) {
                  LogUtils.log(ScreenshotUtils.class, Log.VERBOSE, "Wrote bitmap to %s.",
                          outFile.getAbsolutePath());
                  return outFile;
              } else {
                  LogUtils.log(ScreenshotUtils.class, Log.WARN,
                          "Bitmap failed to compress to file %s.", outFile.getAbsolutePath());
                  return null;
              }
          } catch (IOException e) {
              LogUtils.log(ScreenshotUtils.class, Log.WARN,
                      "Could not output bitmap file to %s.", outFile.getAbsolutePath());
              return null;
          } finally {
              if (outStream != null) {
                  try {
                      outStream.close();
                  } catch (IOException e) {
                      LogUtils.log(ScreenshotUtils.class, Log.WARN, "Unable to close resource.");
                  }
              }
          }
      }
docs: Writes a {@link Bitmap} object to a file in the current context to the given directory.
  
  @param bitmap The bitmap object to output.
  @param filename The name of the file to output.
  @param dirFile The directory {@link File} into which to write the bitmap.
  @return A file where the Bitmap was stored, or {@code null} if the write
  operation failed.