Mohitt Mohitt - 2 years ago 164
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 Source
        File f3=new File(Environment.getExternalStorageDirectory()+"/inpaint/");
        OutputStream outStream = null;
        File file = new File(Environment.getExternalStorageDirectory() + "/inpaint/"+"seconds"+".png");
    try {
        outStream = new FileOutputStream(file);
        mBitmap.compress(Bitmap.CompressFormat.PNG, 85, outStream);

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

       } catch (Exception e) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download