我有一个字节数组形式的 jpeg 图像。如何以可以剥离元数据的注释节点的形式获取字节数组?
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);
}