下面列出了javax.imageio.metadata.IIOMetadataNode#getAttribute ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static ITXtTest getFromNode(IIOMetadataNode n) {
ITXtTest t = new ITXtTest();
if (!"iTXt".equals(n.getNodeName())) {
throw new RuntimeException("Invalid node");
}
IIOMetadataNode e = (IIOMetadataNode)n.getFirstChild();
if (!"iTXtEntry".equals(e.getNodeName())) {
throw new RuntimeException("Invalid entry node");
}
t.keyword = e.getAttribute("keyword");
t.isCompressed =
Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
t.compression =
Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
t.language = e.getAttribute("languageTag");
t.trasKeyword = e.getAttribute("translatedKeyword");
t.text = e.getAttribute("text");
return t;
}
public static ITXtTest getFromNode(IIOMetadataNode n) {
ITXtTest t = new ITXtTest();
if (!"iTXt".equals(n.getNodeName())) {
throw new RuntimeException("Invalid node");
}
IIOMetadataNode e = (IIOMetadataNode)n.getFirstChild();
if (!"iTXtEntry".equals(e.getNodeName())) {
throw new RuntimeException("Invalid entry node");
}
t.keyword = e.getAttribute("keyword");
t.isCompressed =
Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
t.compression =
Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
t.language = e.getAttribute("languageTag");
t.trasKeyword = e.getAttribute("translatedKeyword");
t.text = e.getAttribute("text");
return t;
}
public static ITXtTest getFromNode(IIOMetadataNode n) {
ITXtTest t = new ITXtTest();
if (!"iTXt".equals(n.getNodeName())) {
throw new RuntimeException("Invalid node");
}
IIOMetadataNode e = (IIOMetadataNode)n.getFirstChild();
if (!"iTXtEntry".equals(e.getNodeName())) {
throw new RuntimeException("Invalid entry node");
}
t.keyword = e.getAttribute("keyword");
t.isCompressed =
Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
t.compression =
Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
t.language = e.getAttribute("languageTag");
t.trasKeyword = e.getAttribute("translatedKeyword");
t.text = e.getAttribute("text");
return t;
}
public static ITXtTest getFromNode(IIOMetadataNode n) {
ITXtTest t = new ITXtTest();
if (!"iTXt".equals(n.getNodeName())) {
throw new RuntimeException("Invalid node");
}
IIOMetadataNode e = (IIOMetadataNode)n.getFirstChild();
if (!"iTXtEntry".equals(e.getNodeName())) {
throw new RuntimeException("Invalid entry node");
}
t.keyword = e.getAttribute("keyword");
t.isCompressed =
Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
t.compression =
Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
t.language = e.getAttribute("languageTag");
t.trasKeyword = e.getAttribute("translatedKeyword");
t.text = e.getAttribute("text");
return t;
}
public static ITXtTest getFromNode(IIOMetadataNode n) {
ITXtTest t = new ITXtTest();
if (!"iTXt".equals(n.getNodeName())) {
throw new RuntimeException("Invalid node");
}
IIOMetadataNode e = (IIOMetadataNode)n.getFirstChild();
if (!"iTXtEntry".equals(e.getNodeName())) {
throw new RuntimeException("Invalid entry node");
}
t.keyword = e.getAttribute("keyword");
t.isCompressed =
Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
t.compression =
Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
t.language = e.getAttribute("languageTag");
t.trasKeyword = e.getAttribute("translatedKeyword");
t.text = e.getAttribute("text");
return t;
}
public static void main(String[] args) throws IOException {
String fileName = "nomarkers.jpg";
String sep = System.getProperty("file.separator");
String dir = System.getProperty("test.src", ".");
String filePath = dir+sep+fileName;
System.out.println("Test file: " + filePath);
File file = new File(filePath);
ImageInputStream stream = ImageIO.createImageInputStream(file);
Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
if(readers.hasNext()) {
ImageReader reader = readers.next();
reader.setInput(stream);
IIOMetadata metadata = reader.getImageMetadata(0);
IIOMetadataNode standardTree = (IIOMetadataNode)
metadata.getAsTree
(IIOMetadataFormatImpl.standardMetadataFormatName);
IIOMetadataNode colorSpaceType = (IIOMetadataNode)
standardTree.getElementsByTagName("ColorSpaceType").item(0);
String colorSpaceName = colorSpaceType.getAttribute("name");
if(colorSpaceName.equals("RGB"))
throw new RuntimeException("Identified incorrect ColorSpace");
}
}
public static ITXtTest getFromNode(IIOMetadataNode n) {
ITXtTest t = new ITXtTest();
if (!"iTXt".equals(n.getNodeName())) {
throw new RuntimeException("Invalid node");
}
IIOMetadataNode e = (IIOMetadataNode)n.getFirstChild();
if (!"iTXtEntry".equals(e.getNodeName())) {
throw new RuntimeException("Invalid entry node");
}
t.keyword = e.getAttribute("keyword");
t.isCompressed =
Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
t.compression =
Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
t.language = e.getAttribute("languageTag");
t.trasKeyword = e.getAttribute("translatedKeyword");
t.text = e.getAttribute("text");
return t;
}
public static ITXtTest getFromNode(IIOMetadataNode n) {
ITXtTest t = new ITXtTest();
if (!"iTXt".equals(n.getNodeName())) {
throw new RuntimeException("Invalid node");
}
IIOMetadataNode e = (IIOMetadataNode)n.getFirstChild();
if (!"iTXtEntry".equals(e.getNodeName())) {
throw new RuntimeException("Invalid entry node");
}
t.keyword = e.getAttribute("keyword");
t.isCompressed =
Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
t.compression =
Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
t.language = e.getAttribute("languageTag");
t.trasKeyword = e.getAttribute("translatedKeyword");
t.text = e.getAttribute("text");
return t;
}
public static ITXtTest getFromNode(IIOMetadataNode n) {
ITXtTest t = new ITXtTest();
if (!"iTXt".equals(n.getNodeName())) {
throw new RuntimeException("Invalid node");
}
IIOMetadataNode e = (IIOMetadataNode)n.getFirstChild();
if (!"iTXtEntry".equals(e.getNodeName())) {
throw new RuntimeException("Invalid entry node");
}
t.keyword = e.getAttribute("keyword");
t.isCompressed =
Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
t.compression =
Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
t.language = e.getAttribute("languageTag");
t.trasKeyword = e.getAttribute("translatedKeyword");
t.text = e.getAttribute("text");
return t;
}
public static ITXtTest getFromNode(IIOMetadataNode n) {
ITXtTest t = new ITXtTest();
if (!"iTXt".equals(n.getNodeName())) {
throw new RuntimeException("Invalid node");
}
IIOMetadataNode e = (IIOMetadataNode)n.getFirstChild();
if (!"iTXtEntry".equals(e.getNodeName())) {
throw new RuntimeException("Invalid entry node");
}
t.keyword = e.getAttribute("keyword");
t.isCompressed =
Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
t.compression =
Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
t.language = e.getAttribute("languageTag");
t.trasKeyword = e.getAttribute("translatedKeyword");
t.text = e.getAttribute("text");
return t;
}
public static ITXtTest getFromNode(IIOMetadataNode n) {
ITXtTest t = new ITXtTest();
if (!"iTXt".equals(n.getNodeName())) {
throw new RuntimeException("Invalid node");
}
IIOMetadataNode e = (IIOMetadataNode)n.getFirstChild();
if (!"iTXtEntry".equals(e.getNodeName())) {
throw new RuntimeException("Invalid entry node");
}
t.keyword = e.getAttribute("keyword");
t.isCompressed =
Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
t.compression =
Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
t.language = e.getAttribute("languageTag");
t.trasKeyword = e.getAttribute("translatedKeyword");
t.text = e.getAttribute("text");
return t;
}
public static ITXtTest getFromNode(IIOMetadataNode n) {
ITXtTest t = new ITXtTest();
if (!"iTXt".equals(n.getNodeName())) {
throw new RuntimeException("Invalid node");
}
IIOMetadataNode e = (IIOMetadataNode)n.getFirstChild();
if (!"iTXtEntry".equals(e.getNodeName())) {
throw new RuntimeException("Invalid entry node");
}
t.keyword = e.getAttribute("keyword");
t.isCompressed =
Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
t.compression =
Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
t.language = e.getAttribute("languageTag");
t.trasKeyword = e.getAttribute("translatedKeyword");
t.text = e.getAttribute("text");
return t;
}
public static ITXtTest getFromNode(IIOMetadataNode n) {
ITXtTest t = new ITXtTest();
if (!"iTXt".equals(n.getNodeName())) {
throw new RuntimeException("Invalid node");
}
IIOMetadataNode e = (IIOMetadataNode)n.getFirstChild();
if (!"iTXtEntry".equals(e.getNodeName())) {
throw new RuntimeException("Invalid entry node");
}
t.keyword = e.getAttribute("keyword");
t.isCompressed =
Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
t.compression =
Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
t.language = e.getAttribute("languageTag");
t.trasKeyword = e.getAttribute("translatedKeyword");
t.text = e.getAttribute("text");
return t;
}
public static ITXtTest getFromNode(IIOMetadataNode n) {
ITXtTest t = new ITXtTest();
if (!"iTXt".equals(n.getNodeName())) {
throw new RuntimeException("Invalid node");
}
IIOMetadataNode e = (IIOMetadataNode)n.getFirstChild();
if (!"iTXtEntry".equals(e.getNodeName())) {
throw new RuntimeException("Invalid entry node");
}
t.keyword = e.getAttribute("keyword");
t.isCompressed =
Boolean.valueOf(e.getAttribute("compressionFlag")).booleanValue();
t.compression =
Integer.valueOf(e.getAttribute("compressionMethod")).intValue();
t.language = e.getAttribute("languageTag");
t.trasKeyword = e.getAttribute("translatedKeyword");
t.text = e.getAttribute("text");
return t;
}
@SuppressWarnings("nls")
private void parseExifMeta( IIOMetadata exifMeta ) {
outTags = new HashMap<String, ExifTag>();
IIOMetadataNode root = (IIOMetadataNode) exifMeta.getAsTree("com_sun_media_imageio_plugins_tiff_image_1.0");
NodeList imageDirectories = root.getElementsByTagName("TIFFIFD");
for( int i = 0; i < imageDirectories.getLength(); i++ ) {
IIOMetadataNode directory = (IIOMetadataNode) imageDirectories.item(i);
NodeList tiffTags = directory.getElementsByTagName("TIFFField");
for( int j = 0; j < tiffTags.getLength(); j++ ) {
IIOMetadataNode tag = (IIOMetadataNode) tiffTags.item(j);
String tagNumber = tag.getAttribute("number");
String tagName = tag.getAttribute("name");
String tagValue;
StringBuilder tmp = new StringBuilder();
IIOMetadataNode values = (IIOMetadataNode) tag.getFirstChild();
if ("TIFFUndefined".equals(values.getNodeName())) {
tmp.append(values.getAttribute("value"));
} else {
NodeList tiffNumbers = values.getChildNodes();
for( int k = 0; k < tiffNumbers.getLength(); k++ ) {
tmp.append(((IIOMetadataNode) tiffNumbers.item(k)).getAttribute("value"));
tmp.append(",");
}
tmp.deleteCharAt(tmp.length() - 1);
}
tagValue = tmp.toString();
ExifTag exifTag = new ExifTag(tagName, tagNumber, tagValue);
outTags.put(tagName, exifTag);
}
}
}