3

I'm using an app to get the gps location and draw it as a circle on a bitmap then save it to proceed, so I need repetitively to read and save the file. But unfortunately when I save the file and read it, the file is damaged after some iterations...!
the code:

File output = new File(tmpDirectory, "map.jpg");
    try {
        OutputStream outputStream = new FileOutputStream(output);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
        outputStream.flush();
        outputStream.close();
    } catch (Exception ex) {
        Message("error!");
    }

    directory = tmpDirectory;//updating directory to load the manipulated image
    readFile(directory + "map.jpg", false);//setting the image view new image

image included:picture after iterations image included: main image

Mahdi_Alavi
  • 45
  • 1
  • 2
  • 8
  • 1
    "I'm using an app to get the gps location and draw it as a circle on a bitmap then save it to proceed, so I need repetitively to read and save the file" -- why do you need to "repetitively to read and save the file"? You already have the `Bitmap`. You do not need to read it again to use that `Bitmap`. – CommonsWare May 26 '17 at 13:07

1 Answers1

6

JPEG uses lossy compression. That means with each iteration you will lose some quality. You should use loseless format like PNG if you want to preserve it.

bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159