【问题标题】:bitmap.compress destroys the picture qualitybitmap.compress 破坏图片质量
【发布时间】:2017-10-27 09:19:24
【问题描述】:

我正在使用一个应用程序来获取 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

【问题讨论】:

  • “我正在使用应用程序获取 gps 位置并将其绘制为位图上的圆圈,然后保存以继续,因此我需要重复读取和保存文件”- 为什么要您需要“反复读取和保存文件”吗?您已经拥有Bitmap。您无需再次阅读即可使用 Bitmap

标签: android bitmap jpeg outputstream image-compression


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多