Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 879
Mohitt Avatar asked Apr 01 '14 09:04

Mohitt


People also ask

What is bitmap image 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.


1 Answers

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

like image 94
sharma_kunal Avatar answered Nov 03 '22 00:11

sharma_kunal