android - bitmap.compress 破坏画质

标签 android bitmap jpeg outputstream image-compression

我正在使用一个应用程序来获取 gps 位置并将其绘制为位图上的圆圈然后保存以继续,因此我需要重复读取和保存文件。但不幸的是,当我保存文件并读取它时,文件在一些迭代后被损坏了......!
代码:

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

包含图像:picture after iterations 图片包括: main image

最佳答案

JPEG 使用有损压缩。这意味着每次迭代都会损失一些质量。如果你想保存它,你应该使用像 PNG 这样的无损格式。

bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);

关于android - bitmap.compress 破坏画质,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44202266/

相关文章:

android - 在倒计时结束前播放声音

android - 无法在 Android Studio 的终端中使用 git

android - 使用flutter获取simcard信息

java - 不必要的缩放图像

android - 如何更改发布 APK 神器的路径?

android - 下落图像的数量不确定...在 SurfaceView 上显示 帮助!

android - 如何将图像添加到位图

memory - 矩阵如何存储在内存中?

Python 为初学者读取二进制的 .jpg 文件

image - 如何检测 jpg jpeg 图像文件是否损坏(不完整)?