@Nullable
    public static File scaleAndCompressImageToTemporaryFile(@NonNull final Uri imageUri, final int maxXY, final int compressQuality) {

        final Bitmap image = readImage(imageUri);
        if (image == null) {
            return null;
        }

        final File targetFile = FileUtils.getUniqueNamedFile(new File(LocalStorage.getExternalPrivateCgeoDirectory(), "temporary_image.jpg"));
        final Uri newImageUri = Uri.fromFile(targetFile);
        if (newImageUri == null) {
            Log.e("ImageUtils.readScaleAndWriteImage: unable to write scaled image");
            return null;
        }

        final Bitmap scaledImage = scaleBitmapTo(image, maxXY, maxXY).getBitmap();
        final ViewOrientation orientation = getImageOrientation(imageUri);
        final Bitmap orientedImage = orientation.isNormal() ? scaledImage : Bitmap.createBitmap(scaledImage, 0, 0, scaledImage.getWidth(), scaledImage.getHeight(), orientation.createOrientationCalculationMatrix(), true);

        storeBitmap(orientedImage, Bitmap.CompressFormat.JPEG, compressQuality <= 0 ? 75 : compressQuality, newImageUri);

        return targetFile;
    }
Store a bitmap to uri.

@param bitmap    The bitmap to store
@param format    The image format
@param quality   The image quality
@param targetUri Path to store to
main/src/main/java/cgeo/geocaching/utils/ImageUtils.java