【问题标题】:Raw image not detected ExifInterface未检测到原始图像 ExifInterface
【发布时间】:2020-11-16 06:43:23
【问题描述】:

我从自定义相机保存图像:

public String getFilename() {
        File file = new File(Environment.getExternalStorageDirectory().getPath(), "Products/Images");
        if (!file.exists()) {
            file.mkdirs();
        }
        String uriSting = (file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".jpg");
        return uriSting;

    }

现在:

public String saveImage(Bitmap bitmap) {
        FileOutputStream out = null;
        String filename = getFilename();

        try {
            out = new FileOutputStream(filename);

            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);

        } catch (FileNotFoundException e) {
            Log.e("Error",e.toString());
            e.printStackTrace();
            return "";
        }
        return  filename;

    }

我在保存图片后在 exifInterface 中使用这个文件名

exif = new ExifInterface(filePath);

但每次都显示在我的日志中Raw image not detectedExif: 0

【问题讨论】:

  • file.mkdirs(); 调整您的代码。检查 mkdirs 的返回值,如果为 false,则停止。返回空值。停止并显示 toast 以通知用户。

标签: android


【解决方案1】:

您将位图压缩为 jpg 文件。

位图不包含 exif 信息。

并且将位图压缩为 jpg 文件不会在文件中添加 exif 标头。

【讨论】:

  • 你能告诉我其他获取图像的方法吗,因为我在捕获BitmapFactory.decodeByteArray(data, 0, data.length);时使用它,这将给出一个位图,我怎样才能得到包含exif信息的东西
  • FileOutputStream ,似乎是当时的选择
  • ????您从“数据”构建位图。那么数据到底是什么?
  • 一旦我的问题得到解决,我将接受您的回答,非常感谢!
  • 您接受了错误的答案。嗯..不是说错了...
【解决方案2】:

BitmapFactory.decodeByteArray(data, 0, data.length);

你有一个很好的字节数组,叫做数据。

这个字节数组包含一个带有exif头的jpg文件的字节。

如果您想将数据保存到文件中,请不要先制作中间位图,因为此时您丢失了 exif 标头。

而是将数据数组中的字节直接保存到文件中。

然后你会得到一个带有exif头的jpg文件。

【讨论】:

    猜你喜欢
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 1970-01-01
    • 2021-08-15
    • 2011-10-17
    • 1970-01-01
    相关资源
    最近更新 更多