Creates a temporary file for the images captured with camera. - Android Graphics

Android examples for Graphics:Image File

Description

Creates a temporary file for the images captured with camera.

Demo Code


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main{
    private static final String CAMERA_IMAGE_FILE_NAME = "image.tmp";
    /**/*from  www .j ava 2  s . c o m*/
     * Creates a temp file for the images captured with camera.
     *
     * @param context context.
     * @return the temp file.
     */
    private static File createEmptyImageTempFile(Context context) {
        File f = new File(context.getFilesDir(), CAMERA_IMAGE_FILE_NAME);
        f.delete();
        FileOutputStream fos = null;
        try {
            fos = context.openFileOutput(CAMERA_IMAGE_FILE_NAME,
                    Context.MODE_WORLD_WRITEABLE);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        return getImageTempFile(context);
    }
    /**
     * Creates a temp file for the images captured with camera.
     *
     * @param context context.
     * @return the temp file.
     */
    public static File getImageTempFile(Context context) {
        return new File(context.getFilesDir(), "image.tmp");
    }
}

Related Tutorials