以字节数组形式从JPEG获取元数据 [英] Getting metadata from JPEG in byte array form

查看:107
本文介绍了以字节数组形式从JPEG获取元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字节数组形式的jpeg图像。如何以我可以剥离元数据的注释节点的形式获取字节数组?

I have a jpeg image in the form of a byte array. How can I get the byte array in a form where I can strip the comments node of the metadata?

byte[] myimagedata = ...

ImageWriter writer = ImageIO.getImageWritersBySuffix("jpeg").next();
ImageReader reader = ImageIO.getImageReader(writer);

//Looking for file here but have byte array
reader.setInput(new FileImageInputStream(new File(Byte array cant go here)));

IIOMetadata imageMetadata = reader.getImageMetadata(0);
Element tree = (Element)   imageMetadata.getAsTree("javax_imageio_jpeg_image_1.0");
NodeList comNL = tree.getElementsByTagName("com");
IIOMetadataNode comNode;
if (comNL.getLength() == 0) {
    comNode = new IIOMetadataNode("com");
    Node markerSequenceNode = tree.getElementsByTagName("markerSequence").item(0);
    markerSequenceNode.insertBefore(comNode,markerSequenceNode.getFirstChild());
} else {
    comNode = (IIOMetadataNode) comNL.item(0);          
}


推荐答案

你似乎是(只是) )询问如何创建 ImageInputStream 从字节数组中读取。从阅读javadocs,我认为这应该工作:

You seem you be (just) asking how to create an ImageInputStream that reads from a byte array. From reading the javadocs, I think this should work:

new MemoryCacheImageInputStream(new ByteArrayInputStream(myimagedata))

FileImageInputStream 类没有允许你阅读的构造函数来自文件系统中的任何文件。

The FileImageInputStream class doesn't have a constructor that allows you to read from anything but a file in the file system.

FileCacheImageInputStream 也是一个选项,但它涉及提供文件系统中用于临时缓存的目录......在这种情况下,这似乎是不可取的。

The FileCacheImageInputStream would also be an option, but it involves providing a directory in the file system for temporary caching ... and that seems undesirable in this context.

这篇关于以字节数组形式从JPEG获取元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆