有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用多个数据包将大量XMP数据插入jpg?

我的问题是,我试图将大量RDF数据插入jpeg图像,特别是XMP头。RDF特定于我的应用程序,具有自定义名称空间等。但是,这不应影响插入RDF的过程。 我可以用少量的RDF数据来实现这一点,但是当我尝试插入任何更大的数据时,我达到了XMP数据包大小的限制

我正在使用Java和Apache Sanselan库,但是我愿意使用其他库

下面是我在测试应用程序中使用的代码,但是我不知道如何将其拆分为多个XMP数据包,以便插入需要插入的所有数据

如有任何正确方向的帮助或指点,将不胜感激:)

谢谢

private static File writeXmpToFile(File file, String xmpXmlAsString)
                throws FileNotFoundException, ImageReadException, IOException,
                ImageWriteException {

        String XmpXmlAsString = xmpXmlAsString;

        File fileWithXmpXml = new File(file.getParent(), file.getName()+ ".added-xmp" + ".jpg");
        OutputStream os = null;
        try {
                os = new BufferedOutputStream(new FileOutputStream(fileWithXmpXml));
                new JpegXmpRewriter().updateXmpXml(new ByteSourceFile(file), os, XmpXmlAsString);
        } finally {
                if (os != null) {
                        os.close();
                }
                os = null;
        }
        return fileWithXmpXml;
}

共 (1) 个答案

  1. # 1 楼答案

    引用Adobe XMP规范第3部分:

    Following the normal rules for JPEG sections, the header plus the following data can be at most 65535 bytes long. If the XMP packet is not split across multiple APP1 sections, the size of the XMP packet can be at most 65502 bytes. It is unusual for XMP to exceed this size; typically, it is around 2 KB.

    If the serialized XMP packet becomes larger than the 64 KB limit, you can divide it into a main portion (StandardXMP) and an extended portion (ExtendedXMP), and store it in multiple JPEG marker segment. A reader must check for the existence of ExtendedXMP, and if it is present, integrate the data with the main XMP. Each portion (standard and extended) is a fully formed XMP metadata tree, although only the standard portion contains a complete packet wrapper. If the data is more than twice the 64 KB limit, the extended portion can also be split and stored in multiple marker segments; in this case, the split portions are not fully formed metadata trees.

    When ExtendedXMP is required, the metadata must be split according to some algorithm that assigns more important data to the main portion, and less important data to the extended portions or portions.

    大多数元数据管理代码目前只处理 标准XMP零件,可安装在单个APP1段中-或 阅读或写作。Exiftool似乎可以使用ExtendedXMP

    了解ExtendedXMP结构以及它如何包含在JPEG multiple中 最后,我回答了一个问题here

    基本上,您需要将整个XMP数据分成两部分:一部分 标准XMP,将与数据包一起装入一个APP1段 包装器和一个扩展的XMP,它也是一个格式良好的XMP,但没有 包包装器。ExtendedXMP部件可以是任何大小,如果 超过单个APP1的限制,它将被拆分并插入到 多个APP1段

    上面链接的代码也可以插入大的 只要将XMP数据分成两部分并保持标准 XMP部件小于一个APP1段限制