本文整理汇总了Java中javax.imageio.metadata.IIOMetadataNode类的典型用法代码示例。如果您正苦于以下问题:Java IIOMetadataNode类的具体用法?Java IIOMetadataNode怎么用?Java IIOMetadataNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IIOMetadataNode类属于javax.imageio.metadata包,在下文中一共展示了IIOMetadataNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: COMMarkerSegment
import javax.imageio.metadata.IIOMetadataNode; //导入依赖的package包/类
/**
* Constructs a marker segment from a native tree node. If the node
* is an <code>IIOMetadataNode</code> and contains a user object,
* that object is used rather than the string attribute. If the
* string attribute is used, the default encoding is used.
*/
COMMarkerSegment(Node node) throws IIOInvalidTreeException{
super(JPEG.COM);
if (node instanceof IIOMetadataNode) {
IIOMetadataNode ourNode = (IIOMetadataNode) node;
data = (byte []) ourNode.getUserObject();
}
if (data == null) {
String comment =
node.getAttributes().getNamedItem("comment").getNodeValue();
if (comment != null) {
data = comment.getBytes(); // Default encoding
} else {
throw new IIOInvalidTreeException("Empty comment node!", node);
}
}
}
示例2: createStandardMetadataNodeTree
import javax.imageio.metadata.IIOMetadataNode; //导入依赖的package包/类
public static IIOMetadataNode createStandardMetadataNodeTree() {
/*
* Create standard metadata tree with creation time in
* Standard(Root)/Document/ImageCreationTime node
*/
IIOMetadataNode createTimeNode = new IIOMetadataNode("ImageCreationTime");
createTimeNode.setAttribute("year", "2016");
createTimeNode.setAttribute("month", "12");
createTimeNode.setAttribute("day", "21");
createTimeNode.setAttribute("hour", "18");
createTimeNode.setAttribute("minute", "30");
createTimeNode.setAttribute("second", "00");
// Create the Document node
IIOMetadataNode documentNode = new IIOMetadataNode("Document");
documentNode.appendChild(createTimeNode);
// Create a root node append the Document node
IIOMetadataNode root = new IIOMetadataNode("javax_imageio_1.0");
root.appendChild(documentNode);
return root;
}
示例3: getNativeNode
import javax.imageio.metadata.IIOMetadataNode; //导入依赖的package包/类
IIOMetadataNode getNativeNode() {
IIOMetadataNode node = new IIOMetadataNode("sos");
node.setAttribute("numScanComponents",
Integer.toString(componentSpecs.length));
node.setAttribute("startSpectralSelection",
Integer.toString(startSpectralSelection));
node.setAttribute("endSpectralSelection",
Integer.toString(endSpectralSelection));
node.setAttribute("approxHigh",
Integer.toString(approxHigh));
node.setAttribute("approxLow",
Integer.toString(approxLow));
for (int i = 0; i < componentSpecs.length; i++) {
node.appendChild(componentSpecs[i].getNativeNode());
}
return node;
}
示例4: getNativeNode
import javax.imageio.metadata.IIOMetadataNode; //导入依赖的package包/类
/**
* Returns a tree of DOM nodes representing this object and any
* subordinate JFXX extension or ICC Profile segments.
*/
IIOMetadataNode getNativeNode() {
IIOMetadataNode node = new IIOMetadataNode("app0JFIF");
node.setAttribute("majorVersion", Integer.toString(majorVersion));
node.setAttribute("minorVersion", Integer.toString(minorVersion));
node.setAttribute("resUnits", Integer.toString(resUnits));
node.setAttribute("Xdensity", Integer.toString(Xdensity));
node.setAttribute("Ydensity", Integer.toString(Ydensity));
node.setAttribute("thumbWidth", Integer.toString(thumbWidth));
node.setAttribute("thumbHeight", Integer.toString(thumbHeight));
if (!extSegments.isEmpty()) {
IIOMetadataNode JFXXnode = new IIOMetadataNode("JFXX");
node.appendChild(JFXXnode);
for (Iterator iter = extSegments.iterator(); iter.hasNext();) {
JFIFExtensionMarkerSegment seg =
(JFIFExtensionMarkerSegment) iter.next();
JFXXnode.appendChild(seg.getNativeNode());
}
}
if (iccSegment != null) {
node.appendChild(iccSegment.getNativeNode());
}
return node;
}
示例5: getNativeNode
import javax.imageio.metadata.IIOMetadataNode; //导入依赖的package包/类
IIOMetadataNode getNativeNode() {
IIOMetadataNode node = new IIOMetadataNode("sof");
node.setAttribute("process", Integer.toString(tag-JPEG.SOF0));
node.setAttribute("samplePrecision",
Integer.toString(samplePrecision));
node.setAttribute("numLines",
Integer.toString(numLines));
node.setAttribute("samplesPerLine",
Integer.toString(samplesPerLine));
node.setAttribute("numFrameComponents",
Integer.toString(componentSpecs.length));
for (int i = 0; i < componentSpecs.length; i++) {
node.appendChild(componentSpecs[i].getNativeNode());
}
return node;
}
示例6: getStandardChromaNode
import javax.imageio.metadata.IIOMetadataNode; //导入依赖的package包/类
protected IIOMetadataNode getStandardChromaNode() {
if ((palette != null) && (paletteSize > 0)) {
IIOMetadataNode node = new IIOMetadataNode("Chroma");
IIOMetadataNode subNode = new IIOMetadataNode("Palette");
int numComps = palette.length / paletteSize;
subNode.setAttribute("value", "" + numComps);
for (int i = 0, j = 0; i < paletteSize; i++) {
IIOMetadataNode subNode1 = new IIOMetadataNode("PaletteEntry");
subNode1.setAttribute("index", ""+i);
subNode1.setAttribute("red", "" + palette[j++]);
subNode1.setAttribute("green", "" + palette[j++]);
subNode1.setAttribute("blue", "" + palette[j++]);
if (numComps == 4 && palette[j] != 0)
subNode1.setAttribute("alpha", "" + palette[j++]);
subNode.appendChild(subNode1);
}
node.appendChild(subNode);
return node;
}
return null;
}
示例7: getStandardDataNode
import javax.imageio.metadata.IIOMetadataNode; //导入依赖的package包/类
protected IIOMetadataNode getStandardDataNode() {
IIOMetadataNode node = new IIOMetadataNode("Data");
String bits = "";
if (bitsPerPixel == 24)
bits = "8 8 8 ";
else if (bitsPerPixel == 16 || bitsPerPixel == 32) {
bits = "" + countBits(redMask) + " " + countBits(greenMask) +
countBits(blueMask) + "" + countBits(alphaMask);
}
IIOMetadataNode subNode = new IIOMetadataNode("BitsPerSample");
subNode.setAttribute("value", bits);
node.appendChild(subNode);
return node;
}
示例8: gethISTNode
import javax.imageio.metadata.IIOMetadataNode; //导入依赖的package包/类
private IIOMetadataNode gethISTNode(BufferedImage bi) {
IndexColorModel icm = (IndexColorModel)bi.getColorModel();
int mapSize = icm.getMapSize();
int[] hist = new int[mapSize];
Arrays.fill(hist, 0);
Raster r = bi.getData();
for (int y = 0; y < bi.getHeight(); y++) {
for (int x = 0; x < bi.getWidth(); x++) {
int s = r.getSample(x, y, 0);
hist[s] ++;
}
}
IIOMetadataNode hIST = new IIOMetadataNode("hIST");
for (int i = 0; i < hist.length; i++) {
IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
n.setAttribute("index", "" + i);
n.setAttribute("value", "" + hist[i]);
hIST.appendChild(n);
}
return hIST;
}
示例9: test1
import javax.imageio.metadata.IIOMetadataNode; //导入依赖的package包/类
public static void test1() {
IIOMetadataNode parent = new IIOMetadataNode("parent");
IIOMetadataNode elem = new IIOMetadataNode("elem");
MyAttrNode attrNode = new MyAttrNode("name", "value");
elem.setAttributeNode(attrNode);
attrNode.setOwnerElement(elem);
try {
parent.setAttributeNode(attrNode);
} catch (DOMException e) {
if (e.code != DOMException.INUSE_ATTRIBUTE_ERR) {
throw new RuntimeException("Test 1 failed: " +
"Invalid exception code: " +
e.code);
}
return;
}
throw new RuntimeException("Test 1 failed: DOMException not thrown");
}
示例10: readFrom
import javax.imageio.metadata.IIOMetadataNode; //导入依赖的package包/类
private static ITXtTest readFrom(File f) {
try (ImageInputStream imageInputStream =
ImageIO.createImageInputStream(f)) {
ImageReader r = ImageIO.getImageReaders(imageInputStream).next();
r.setInput(imageInputStream);
IIOImage dst = r.readAll(0, null);
// look for iTXt node
IIOMetadata m = dst.getMetadata();
Node root = m.getAsTree(m.getNativeMetadataFormatName());
Node n = root.getFirstChild();
while (n != null && !"iTXt".equals(n.getNodeName())) {
n = n.getNextSibling();
}
if (n == null) {
throw new RuntimeException("No iTXt node!");
}
ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n);
return t;
} catch (Throwable e) {
throw new RuntimeException("Reading test failed.", e);
}
}
示例11: test2
import javax.imageio.metadata.IIOMetadataNode; //导入依赖的package包/类
public static void test2() {
String name = "attr";
String oldValue = "old value";
String newValue = "new value";
Attr retAttr;
IIOMetadataNode parent = new IIOMetadataNode("parent");
MyAttrNode attrNode1 = new MyAttrNode(name, oldValue);
MyAttrNode attrNode2 = new MyAttrNode(name, newValue);
retAttr = parent.setAttributeNode(attrNode1);
retAttr = parent.setAttributeNode(attrNode2);
String actName = retAttr.getNodeName();
String actValue = retAttr.getValue();
if (!actName.equals(name) || !actValue.equals(oldValue)) {
throw new RuntimeException("Test 2 failed: Invalid attribute " +
"returned: " +
"(name: " + actName +
", value: " + actValue + ")");
}
}
示例12: test4
import javax.imageio.metadata.IIOMetadataNode; //导入依赖的package包/类
public static void test4() {
String name = "name";
String correctValue = "correct value";
String wrongValue = "wrong value";
IIOMetadataNode parent = new IIOMetadataNode("parent");
MyAttrNode attrNode1 = new MyAttrNode(name, wrongValue);
MyAttrNode attrNode2 = new MyAttrNode(name, correctValue);
parent.setAttributeNode(attrNode1);
parent.setAttributeNode(attrNode2);
Attr actAttr = parent.getAttributeNode(name);
String actValue = actAttr.getValue();
if (!actValue.equals(correctValue)) {
throw new RuntimeException("Test 4 failed: Return value is: " +
actValue);
}
}
示例13: 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;
}
示例14: readFrom
import javax.imageio.metadata.IIOMetadataNode; //导入依赖的package包/类
private static ITXtTest readFrom(File f) {
try {
ImageInputStream iis = ImageIO.createImageInputStream(f);
ImageReader r = ImageIO.getImageReaders(iis).next();
r.setInput(iis);
IIOImage dst = r.readAll(0, null);
// look for iTXt node
IIOMetadata m = dst.getMetadata();
Node root = m.getAsTree(m.getNativeMetadataFormatName());
Node n = root.getFirstChild();
while (n != null && !"iTXt".equals(n.getNodeName())) {
n = n.getNextSibling();
}
if (n == null) {
throw new RuntimeException("No iTXt node!");
}
ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n);
return t;
} catch (Throwable e) {
throw new RuntimeException("Reading test failed.", e);
}
}
示例15: COMMarkerSegment
import javax.imageio.metadata.IIOMetadataNode; //导入依赖的package包/类
/**
* Constructs a marker segment from a native tree node. If the node
* is an {@code IIOMetadataNode} and contains a user object,
* that object is used rather than the string attribute. If the
* string attribute is used, the default encoding is used.
*/
COMMarkerSegment(Node node) throws IIOInvalidTreeException{
super(JPEG.COM);
if (node instanceof IIOMetadataNode) {
IIOMetadataNode ourNode = (IIOMetadataNode) node;
data = (byte []) ourNode.getUserObject();
}
if (data == null) {
String comment =
node.getAttributes().getNamedItem("comment").getNodeValue();
if (comment != null) {
data = comment.getBytes(); // Default encoding
} else {
throw new IIOInvalidTreeException("Empty comment node!", node);
}
}
}