How to save an image on Android without compressing it?


I'm making an Android application that captures images and saves them in the internal memory, but when I save them the images are compressed and I want them to be saved in original size without any kind of understanding.

this is the code I'm using to save the images, how do I not compress them?

public File saveToInternalStorage(Context context, Bitmap bitmapImage) {
        ContextWrapper cw = new ContextWrapper(context);

        File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);

        File mypath = new File(directory, "TheChat" + (System.currentTimeMillis()/1000) + "Avatar.jpg");

        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(mypath);
            bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
        catch (Exception e) {
        finally {
            try {
                if (fileOutputStream != null) {
            } catch (IOException e) {
        return mypath;
asked by Sneyder Angulo 10.09.2016 в 23:28

1 answer


To save the image without compressing it, simply save it in .png format, in which compression does not apply and of course, define 100% quality:

bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream ); 
answered by 11.09.2016 в 02:03