本文整理匯總了Java中javax.imageio.metadata.IIOMetadata.mergeTree方法的典型用法代碼示例。如果您正苦於以下問題:Java IIOMetadata.mergeTree方法的具體用法?Java IIOMetadata.mergeTree怎麽用?Java IIOMetadata.mergeTree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.imageio.metadata.IIOMetadata
的用法示例。
在下文中一共展示了IIOMetadata.mergeTree方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String format = "javax_imageio_1.0";
BufferedImage img =
new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();
IIOMetadata meta =
iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null);
DOMImplementationRegistry registry;
registry = DOMImplementationRegistry.newInstance();
DOMImplementation impl = registry.getDOMImplementation("XML 3.0");
Document doc = impl.createDocument(null, format, null);
Element root, text, entry;
root = doc.getDocumentElement();
root.appendChild(text = doc.createElement("Text"));
text.appendChild(entry = doc.createElement("TextEntry"));
// keyword isn't #REQUIRED by the standard metadata format.
// However, it is required by the PNG format, so we include it here.
entry.setAttribute("keyword", "Comment");
entry.setAttribute("value", "Some demo comment");
meta.mergeTree(format, root);
}
示例2: upgradeMetadata
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
private IIOMetadata upgradeMetadata(IIOMetadata src, BufferedImage bi) {
String format = src.getNativeMetadataFormatName();
System.out.println("Native format: " + format);
Node root = src.getAsTree(format);
// add hIST node
Node n = lookupChildNode(root, "hIST");
if (n == null) {
System.out.println("Appending new hIST node...");
Node hIST = gethISTNode(bi);
root.appendChild(hIST);
}
System.out.println("Upgraded metadata tree:");
dump(root, "");
System.out.println("Merging metadata...");
try {
src.mergeTree(format, root);
} catch (IIOInvalidTreeException e) {
throw new RuntimeException("Test FAILED!", e);
}
return src;
}
示例3: convertMetadata
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
/**
* Merges <code>inData</code> into <code>outData</code>. The supplied
* metadata format name is attempted first and failing that the standard
* metadata format name is attempted.
*/
private void convertMetadata(String metadataFormatName,
IIOMetadata inData,
IIOMetadata outData) {
String formatName = null;
String nativeFormatName = inData.getNativeMetadataFormatName();
if (nativeFormatName != null &&
nativeFormatName.equals(metadataFormatName)) {
formatName = metadataFormatName;
} else {
String[] extraFormatNames = inData.getExtraMetadataFormatNames();
if (extraFormatNames != null) {
for (int i = 0; i < extraFormatNames.length; i++) {
if (extraFormatNames[i].equals(metadataFormatName)) {
formatName = metadataFormatName;
break;
}
}
}
}
if (formatName == null &&
inData.isStandardMetadataFormatSupported()) {
formatName = STANDARD_METADATA_NAME;
}
if (formatName != null) {
try {
Node root = inData.getAsTree(formatName);
outData.mergeTree(formatName, root);
} catch(IIOInvalidTreeException e) {
// ignore
}
}
}
示例4: convertMetadata
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
/**
* Merges {@code inData} into {@code outData}. The supplied
* metadata format name is attempted first and failing that the standard
* metadata format name is attempted.
*/
private void convertMetadata(String metadataFormatName,
IIOMetadata inData,
IIOMetadata outData) {
String formatName = null;
String nativeFormatName = inData.getNativeMetadataFormatName();
if (nativeFormatName != null &&
nativeFormatName.equals(metadataFormatName)) {
formatName = metadataFormatName;
} else {
String[] extraFormatNames = inData.getExtraMetadataFormatNames();
if (extraFormatNames != null) {
for (int i = 0; i < extraFormatNames.length; i++) {
if (extraFormatNames[i].equals(metadataFormatName)) {
formatName = metadataFormatName;
break;
}
}
}
}
if (formatName == null &&
inData.isStandardMetadataFormatSupported()) {
formatName = STANDARD_METADATA_NAME;
}
if (formatName != null) {
try {
Node root = inData.getAsTree(formatName);
outData.mergeTree(formatName, root);
} catch(IIOInvalidTreeException e) {
// ignore
}
}
}
示例5: main
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
ImageWriter iw =
(ImageWriter)ImageIO.getImageWritersByFormatName("jpeg").next();
ImageTypeSpecifier type =
ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
ImageOutputStream ios =
ImageIO.createImageOutputStream(new File("MergeTreeTest.jpeg"));
iw.setOutput(ios);
IIOMetadata meta = iw.getDefaultImageMetadata(type, null);
boolean isFailed = false;
String[] fmts = meta.getMetadataFormatNames();
for (int i=0; i<fmts.length; i++) {
System.out.print("Format: " + fmts[i] + " ... ");
Node root = meta.getAsTree(fmts[i]);
try {
meta.mergeTree(fmts[i], root);
} catch (NullPointerException e) {
throw new RuntimeException("Test failed for format " + fmts[i], e);
}
System.out.println("PASSED");
}
}
示例6: test
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
public static void test(String mimeType, boolean useStreamMeta,
String metaXml, String... boolXpaths)
throws Exception
{
BufferedImage img =
new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
ImageWriter iw = ImageIO.getImageWritersByMIMEType(mimeType).next();
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageOutputStream ios = new MemoryCacheImageOutputStream(os);
iw.setOutput(ios);
ImageWriteParam param = null;
IIOMetadata streamMeta = iw.getDefaultStreamMetadata(param);
IIOMetadata imageMeta =
iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);
IIOMetadata meta = useStreamMeta ? streamMeta : imageMeta;
Source src = new StreamSource(new StringReader(metaXml));
DOMResult dst = new DOMResult();
transform(src, dst);
Document doc = (Document)dst.getNode();
Element node = doc.getDocumentElement();
String metaFormat = node.getNodeName();
// Verify that the default metadata gets formatted correctly.
verify(meta.getAsTree(metaFormat), boolXpaths, false);
meta.mergeTree(metaFormat, node);
// Verify that the merged metadata gets formatte correctly.
verify(meta.getAsTree(metaFormat), boolXpaths, true);
iw.write(streamMeta, new IIOImage(img, null, imageMeta), param);
iw.dispose();
ios.close();
ImageReader ir = ImageIO.getImageReader(iw);
byte[] bytes = os.toByteArray();
if (bytes.length == 0)
throw new AssertionError("Zero length image file");
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
ImageInputStream iis = new MemoryCacheImageInputStream(is);
ir.setInput(iis);
if (useStreamMeta) meta = ir.getStreamMetadata();
else meta = ir.getImageMetadata(0);
// Verify again after writing and re-reading the image
verify(meta.getAsTree(metaFormat), boolXpaths, true);
}
示例7: createTestPng
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
private static byte[] createTestPng() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedImage img = createTestImage();
try {
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
ImageWriter w = ImageIO.getImageWritersByFormatName("PNG").next();
w.setOutput(ios);
ImageWriteParam p = w.getDefaultWriteParam();
ImageTypeSpecifier t = ImageTypeSpecifier.createFromRenderedImage(img);
IIOMetadata m = w.getDefaultImageMetadata(t, p);
String nativeMetadataFormat = m.getNativeMetadataFormatName();
Node root = m.getAsTree(nativeMetadataFormat);
IIOMetadataNode textEntry = new IIOMetadataNode("tEXtEntry");
textEntry.setAttribute("keyword", "comment");
textEntry.setAttribute("value", "This is a test image for JDK-6945174");
IIOMetadataNode text = new IIOMetadataNode("tEXt");
text.appendChild(textEntry);
root.appendChild(text);
m.mergeTree(nativeMetadataFormat, root);
IIOImage iio_img = new IIOImage(img, null, m);
w.write(iio_img);
w.dispose();
ios.flush();
ios.close();
} catch (IOException e) {
throw new RuntimeException("Test failed.", e);
}
baos.flush();
byte[] data = baos.toByteArray();
adjustCommentLength(Integer.MAX_VALUE + 0x1000, data);
return data;
}