2

I'm making an Android application that captures images and stores them in the internal memory, but to save the images are compressed and I want to be saved in its original size without any compression.

This is the code I am using to store images, as I do so not me compress ??

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) {
    e.printStackTrace();
}
finally {
    try {
        if (fileOutputStream != null) {
            fileOutputStream.flush();
            fileOutputStream.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
2
  • 2
    What file format are you planning on using for the image? Most file formats used by programmers are compressed, such as PNG, JPEG, GIF, and WebP. Commented Sep 11, 2016 at 18:48
  • Why do you prefer no compression over lossless compression? Commented Sep 11, 2016 at 21:03

1 Answer 1

2

Save it as a BLOB (bytearray), then reconvert it to a bitmap upon loading it. If it's for internal use only it should work fine. If you're not compressing it at all you might as well save it in a straight-forward format.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.