Mohitt Mohitt - 1 month ago 25
Android Question

Android saving bitmap image temporarily

I am looking out for a way to save a bitmap file temporarily in android file system. The file is required only until it is used as a part of POST request to a server after which I want it to cease to exist. I am looking for the faster way of doing this.

...
File file = new File(Environment.getExternalStorageDirectory().getPath().toString()+"/ImageDB/" + fileName+".png");
FileOutputStream filecon = new FileOutputStream(file);
sampleResized.compress(Bitmap.CompressFormat.JPEG, 90, filecon);
...


I am currently using this method.

EDIT: I got my solution from Creating temporary files in Android

Answer
        File f3=new File(Environment.getExternalStorageDirectory()+"/inpaint/");
        if(!f3.exists()){
            f3.mkdirs();
        }       
        OutputStream outStream = null;
        File file = new File(Environment.getExternalStorageDirectory() + "/inpaint/"+"seconds"+".png");
    try {
        outStream = new FileOutputStream(file);
        mBitmap.compress(Bitmap.CompressFormat.PNG, 85, outStream);
        outStream.flush();
        outStream.close();

        Toast.makeText(getApplicationContext(), "Saved", Toast.LENGTH_LONG).show();

       } catch (Exception e) {
        e.printStackTrace();
       }