如何在不损失质量的情况下从图像(JPG)中删除元数据?

4

我在Stackoverflow上找到了一个类似的问题:

如何在Java中从JPEG图像中删除元数据?

但是当我使用上面描述的方法时,保存的图像被压缩了。有没有办法在不压缩图像的情况下删除元数据?是否有任何库可以在我的Java程序中使用?

1个回答

4

好的,我最终通过使用Apache“commons-imaging”找到了解决方案:

https://svn.apache.org/repos/asf/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/examples/WriteExifMetadataExample.java

    public void removeExifMetadata(final File jpegImageFile, final File dst)
        throws IOException, ImageReadException, ImageWriteException {
    OutputStream os = null;
    try {
        os = new FileOutputStream(dst);
        os = new BufferedOutputStream(os);

        new ExifRewriter().removeExifMetadata(jpegImageFile, os);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (final IOException e) {

            }
        }
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接