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
A bitmap (or raster graphic) is a digital image composed of a matrix of dots. When viewed at 100%, each dot corresponds to an individual pixel on a display. In a standard bitmap image, each dot can be assigned a different color. In this instance we will simply create a Bitmap directly: Bitmap b = Bitmap.
Please check the below code. All the above codes are right. But if we compress JPEG it work fast as compare to PNG. So Better to use JPEG to imporove performance..
FileOutputStream fileOutputStream = new FileOutputStream(path);
BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
viewCapture.compress(CompressFormat.JPEG, 50, bos);
bos.flush();
bos.close();
For Delete just use
File myFile = new File(path);
myFile.delete();
Hope its helpfull for you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With