本文整理匯總了Java中javax.imageio.metadata.IIOMetadata.getAsTree方法的典型用法代碼示例。如果您正苦於以下問題:Java IIOMetadata.getAsTree方法的具體用法?Java IIOMetadata.getAsTree怎麽用?Java IIOMetadata.getAsTree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.imageio.metadata.IIOMetadata
的用法示例。
在下文中一共展示了IIOMetadata.getAsTree方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeHeader
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
private void writeHeader(IIOMetadata streamMetadata, int bitsPerPixel)
throws IOException {
GIFWritableStreamMetadata sm;
if (streamMetadata instanceof GIFWritableStreamMetadata) {
sm = (GIFWritableStreamMetadata)streamMetadata;
} else {
sm = new GIFWritableStreamMetadata();
Node root =
streamMetadata.getAsTree(STREAM_METADATA_NAME);
sm.setFromTree(STREAM_METADATA_NAME, root);
}
writeHeader(sm.version,
sm.logicalScreenWidth,
sm.logicalScreenHeight,
sm.colorResolution,
sm.pixelAspectRatio,
sm.backgroundColorIndex,
sm.sortFlag,
bitsPerPixel,
sm.globalColorTable);
}
示例2: readFrom
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的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);
}
}
示例3: 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;
}
示例4: convertStandardImageMetadata
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
/**
* Converts a standard {@code javax_imageio_1.0} tree to a
* {@code TIFFImageMetadata} object.
*
* @param inData The metadata object.
* @return a {@code TIFFImageMetadata} or {@code null} if
* the standard tree derived from the input object is {@code null}.
* @throws IllegalArgumentException if {@code inData} is
* {@code null}.
* @throws IllegalArgumentException if {@code inData} does not support
* the standard metadata format.
* @throws IIOInvalidTreeException if {@code inData} generates an
* invalid standard metadata tree.
*/
private TIFFImageMetadata convertStandardImageMetadata(IIOMetadata inData)
throws IIOInvalidTreeException {
if(inData == null) {
throw new NullPointerException("inData == null!");
} else if(!inData.isStandardMetadataFormatSupported()) {
throw new IllegalArgumentException
("inData does not support standard metadata format!");
}
TIFFImageMetadata outData = null;
String formatName = IIOMetadataFormatImpl.standardMetadataFormatName;
Node tree = inData.getAsTree(formatName);
if (tree != null) {
List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
tagSets.add(BaselineTIFFTagSet.getInstance());
outData = new TIFFImageMetadata(tagSets);
outData.setFromTree(formatName, tree);
}
return outData;
}
示例5: convertNativeImageMetadata
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
/**
* Converts a native
* {@code javax_imageio_tiff_image_1.0} tree to a
* {@code TIFFImageMetadata} object.
*
* @param inData The metadata object.
* @return a {@code TIFFImageMetadata} or {@code null} if
* the native tree derived from the input object is {@code null}.
* @throws IllegalArgumentException if {@code inData} is
* {@code null} or does not support the native metadata format.
* @throws IIOInvalidTreeException if {@code inData} generates an
* invalid native metadata tree.
*/
private TIFFImageMetadata convertNativeImageMetadata(IIOMetadata inData)
throws IIOInvalidTreeException {
if(inData == null) {
throw new NullPointerException("inData == null!");
} else if(!Arrays.asList(inData.getMetadataFormatNames()).contains(
TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME)) {
throw new IllegalArgumentException
("inData does not support native metadata format!");
}
TIFFImageMetadata outData = null;
String formatName = TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME;
Node tree = inData.getAsTree(formatName);
if (tree != null) {
List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
tagSets.add(BaselineTIFFTagSet.getInstance());
outData = new TIFFImageMetadata(tagSets);
outData.setFromTree(formatName, tree);
}
return outData;
}
示例6: main
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
// Generate some trivial image and save it to a temporary array
ByteArrayOutputStream tmp = new ByteArrayOutputStream();
ImageIO.write(new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB),
"gif", tmp);
// Read the stream
ImageInputStream in = new MemoryCacheImageInputStream(
new ByteArrayInputStream(tmp.toByteArray()));
ImageReader reader = ImageIO.getImageReaders(in).next();
reader.setInput(in);
// Retrieve standard image metadata tree
IIOMetadata meta = reader.getImageMetadata(0);
if (meta == null || !meta.isStandardMetadataFormatSupported()) {
throw new Error("Test failure: Missing metadata");
}
Element root = (Element) meta.
getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
// Test getElementsByTagName("*")
if (root.getElementsByTagName("*").getLength() == 0) {
throw new RuntimeException("getElementsByTagName(\"*\") returns"
+ " nothing");
}
}
示例7: main
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的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");
}
}
示例8: testGetAsTree
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
public void testGetAsTree() {
ImageWriteParam p = w.getDefaultWriteParam();
IIOMetadata m =
w.getDefaultImageMetadata(ImageTypeSpecifier.createFromBufferedImageType(type), p);
String format = m.getNativeMetadataFormatName();
System.out.println("native format: " + format);
int count = 0;
try {
while (count < 100) {
System.out.println(" test " + count++);
m.getAsTree(format);
}
} catch (OutOfMemoryError e) {
System.gc();
throw new RuntimeException("Test failed. Number of performed operations: " + count, e);
}
}
示例9: paintToPng
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
/**
* Paints this panel to a PNG image with specified resolution and width.
* The image height is computed so that the image has the same aspect
* ratio as this panel.
* @param dpi the image resolution, in dots per inch.
* @param win the image width, in inches.
* @param fileName the name of the file to contain the PNG image.
* @throws IOException when unable to save to file.
*/
public void paintToPng(double dpi, double win, String fileName)
throws IOException
{
BufferedImage image = paintToImage((int)ceil(dpi*win));
// The two lines below are simple, but do not write resolution info to
// the PNG file. We want that info, especially for high-res images.
//File file = new File(fileName);
//ImageIO.write(image,"png",file);
Iterator<ImageWriter> i = ImageIO.getImageWritersBySuffix("png");
if (!i.hasNext())
throw new IOException("cannot get a PNG image writer");
ImageWriter iw = i.next();
FileOutputStream fos = new FileOutputStream(fileName);
ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
iw.setOutput(ios);
ImageWriteParam iwp = iw.getDefaultWriteParam();
ImageTypeSpecifier its = new ImageTypeSpecifier(image);
IIOMetadata imd = iw.getDefaultImageMetadata(its,iwp);
String format = "javax_imageio_png_1.0";
IIOMetadataNode tree = (IIOMetadataNode)imd.getAsTree(format);
IIOMetadataNode node = new IIOMetadataNode("pHYs");
String dpm = Integer.toString((int)ceil(dpi/0.0254));
node.setAttribute("pixelsPerUnitXAxis",dpm);
node.setAttribute("pixelsPerUnitYAxis",dpm);
node.setAttribute("unitSpecifier","meter");
tree.appendChild(node);
imd.setFromTree(format,tree);
iw.write(new IIOImage(image,null,imd));
ios.flush();
ios.close();
fos.flush();
fos.close();
iw.dispose();
}
示例10: 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
}
}
}
示例11: checkColorDepth
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
private void checkColorDepth() {
IIOMetadata dst = iio_dst.getMetadata();
Node data = dst.getAsTree("javax_imageio_bmp_1.0");
Node n = data.getFirstChild();
while (n != null && !("BitsPerPixel".equals(n.getNodeName()))) {
System.out.println("Node " + n.getNodeName());
n = n.getNextSibling();
}
if (n == null) {
throw new RuntimeException("No BitsPerSample node!");
}
int bpp = 0;
String value = n.getNodeValue();
System.out.println("value = " + value);
try {
bpp = Integer.parseInt(value);
} catch (NumberFormatException e) {
throw new RuntimeException("Wrong bpp value: " + value, e);
}
if (bpp != this.expectedColorDepth) {
throw new RuntimeException("Wrong color depth: " + bpp +
" (should be " + this.expectedColorDepth + ")");
}
}
示例12: writeTo
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
private static void writeTo(File f, ITXtTest t) {
BufferedImage src = createBufferedImage();
try (ImageOutputStream imageOutputStream =
ImageIO.createImageOutputStream(f)) {
ImageTypeSpecifier imageTypeSpecifier =
new ImageTypeSpecifier(src);
ImageWriter imageWriter =
ImageIO.getImageWritersByFormatName("PNG").next();
imageWriter.setOutput(imageOutputStream);
IIOMetadata m =
imageWriter.getDefaultImageMetadata(imageTypeSpecifier, null);
String format = m.getNativeMetadataFormatName();
Node root = m.getAsTree(format);
IIOMetadataNode iTXt = t.getNode();
root.appendChild(iTXt);
m.setFromTree(format, root);
imageWriter.write(new IIOImage(src, null, m));
System.out.println("Writing done.");
} catch (Throwable e) {
throw new RuntimeException("Writing test failed.", e);
}
}
示例13: writeTo
import javax.imageio.metadata.IIOMetadata; //導入方法依賴的package包/類
private static void writeTo(File f, ITXtTest t) {
BufferedImage src = createBufferedImage();
try {
ImageOutputStream imageOutputStream =
ImageIO.createImageOutputStream(f);
ImageTypeSpecifier imageTypeSpecifier =
new ImageTypeSpecifier(src);
ImageWriter imageWriter =
ImageIO.getImageWritersByFormatName("PNG").next();
imageWriter.setOutput(imageOutputStream);
IIOMetadata m =
imageWriter.getDefaultImageMetadata(imageTypeSpecifier, null);
String format = m.getNativeMetadataFormatName();
Node root = m.getAsTree(format);
IIOMetadataNode iTXt = t.getNode();
root.appendChild(iTXt);
m.setFromTree(format, root);
imageWriter.write(new IIOImage(src, null, m));
imageOutputStream.close();
System.out.println("Writing done.");
} catch (Throwable e) {
throw new RuntimeException("Writing test failed.", e);
}
}
示例14: 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
}
}
}
示例15: 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");
}
}