Skip to content Skip to sidebar Skip to footer

How To Use Bitmap Factory To Compress Image Without Reduce The Quality Taken From Camera?

I have 3 images taken from camera and I want to set to 3 ImageView. But it throws OutOfMemory because the image has large size. I've read that bitmap factory can compress the size

Solution 1:

Use like this :

File file = new File(Environment.getExternalStorageDirectory(),"imagename.jpg");
fileDeleted = !file.exists() || file.delete();
if (fileDeleted) {
FileOutputStream out = new FileOutputStream(file);
if (imageToSave != null) {
imageToSave.compress(Bitmap.CompressFormat.JPEG, 65, out);
}}
out.flush();
out.close();

Solution 2:

Instead of using the media store which tries to give you a full bitmap you better open an inputstream and load a resized bitmap from it.

InputStream is = getContentResolver().openInputStream(outPutfileUri);

Then use BitmapFactory.decodeStream() with an options parameter where you scale down the image several times.

Post a Comment for "How To Use Bitmap Factory To Compress Image Without Reduce The Quality Taken From Camera?"