本文整理匯總了Java中javax.imageio.metadata.IIOMetadataNode.getAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java IIOMetadataNode.getAttribute方法的具體用法?Java IIOMetadataNode.getAttribute怎麽用?Java IIOMetadataNode.getAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.imageio.metadata.IIOMetadataNode
的用法示例。
在下文中一共展示了IIOMetadataNode.getAttribute方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFromNode
import javax.imageio.metadata.IIOMetadataNode; //導入方法依賴的package包/類
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;
}
示例2: main
import javax.imageio.metadata.IIOMetadataNode; //導入方法依賴的package包/類
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");
}
}