本文整理汇总了Java中javax.imageio.metadata.IIOMetadata.getNativeMetadataFormatName方法的典型用法代码示例。如果您正苦于以下问题:Java IIOMetadata.getNativeMetadataFormatName方法的具体用法?Java IIOMetadata.getNativeMetadataFormatName怎么用?Java IIOMetadata.getNativeMetadataFormatName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.metadata.IIOMetadata
的用法示例。
在下文中一共展示了IIOMetadata.getNativeMetadataFormatName方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
}
示例3: configureMetaData
import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
/**
* Configures the per frame metadata
*
* @param meta the default meta data
* @param delayTime the amount of time a frame is to stay on screen in hundreds of a second (millisecond value/10)
* @param imageIndex the index of this frame
* @throws IIOInvalidTreeException if the meta data cannot be set
*/
private void configureMetaData(IIOMetadata meta, String delayTime, int imageIndex) throws IIOInvalidTreeException {
String metaFormat = meta.getNativeMetadataFormatName();
Node root = meta.getAsTree(metaFormat);
Node child = root.getFirstChild();
while (child != null) {
if ("GraphicControlExtension".equals(child.getNodeName())) {
break;
}
child = child.getNextSibling();
}
IIOMetadataNode gce = (IIOMetadataNode) child;
gce.setAttribute("userDelay", "FALSE");
gce.setAttribute("delayTime", delayTime);
gce.setAttribute("disposalMethod", "none");
if (imageIndex == 0) {
IIOMetadataNode aes = new IIOMetadataNode("ApplicationExtensions");
IIOMetadataNode ae = new IIOMetadataNode("ApplicationExtension");
ae.setAttribute("applicationID", "NETSCAPE");
ae.setAttribute("authenticationCode", "2.0");
byte[] uo = new byte[] { 0x1, (byte) (LOOP_COUNT & 0xFF), (byte) ((LOOP_COUNT >> 8) & 0xFF) };
ae.setUserObject(uo);
aes.appendChild(ae);
root.appendChild(aes);
}
meta.setFromTree(metaFormat, root);
}
示例4: 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
}
}
}
示例5: getMetadata
import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
private IIOMetadata getMetadata(String formatName,
Set nodeNames,
boolean wantStream,
int imageIndex) throws IOException {
if (formatName == null) {
throw new IllegalArgumentException("formatName == null!");
}
if (nodeNames == null) {
throw new IllegalArgumentException("nodeNames == null!");
}
IIOMetadata metadata =
wantStream
? getStreamMetadata()
: getImageMetadata(imageIndex);
if (metadata != null) {
if (metadata.isStandardMetadataFormatSupported() &&
formatName.equals
(IIOMetadataFormatImpl.standardMetadataFormatName)) {
return metadata;
}
String nativeName = metadata.getNativeMetadataFormatName();
if (nativeName != null && formatName.equals(nativeName)) {
return metadata;
}
String[] extraNames = metadata.getExtraMetadataFormatNames();
if (extraNames != null) {
for (int i = 0; i < extraNames.length; i++) {
if (formatName.equals(extraNames[i])) {
return metadata;
}
}
}
}
return null;
}
示例6: main
import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
public static void main(String[] args) throws IIOInvalidTreeException {
// getting the writer for the png format
Iterator iter = ImageIO.getImageWritersByFormatName("png");
ImageWriter writer = (ImageWriter) iter.next();
// creating a color model
ColorModel colorModel = ColorModel.getRGBdefault();
// creating a sample model
SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480);
// creating a default metadata object
IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null);
String formatName = metaData.getNativeMetadataFormatName();
// first call
Node metaDataNode = metaData.getAsTree(formatName);
try {
metaData.setFromTree(formatName, metaDataNode);
} catch (Exception ex) {
ex.printStackTrace();
}
// second call (bitdepht is already set to an invalid value)
metaDataNode = metaData.getAsTree(formatName);
metaData.setFromTree(formatName, metaDataNode);
}
示例7: 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);
}
}
示例8: 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
}
}
}
示例9: getMetadata
import javax.imageio.metadata.IIOMetadata; //导入方法依赖的package包/类
private IIOMetadata getMetadata(String formatName,
Set<String> nodeNames,
boolean wantStream,
int imageIndex) throws IOException {
if (formatName == null) {
throw new IllegalArgumentException("formatName == null!");
}
if (nodeNames == null) {
throw new IllegalArgumentException("nodeNames == null!");
}
IIOMetadata metadata =
wantStream
? getStreamMetadata()
: getImageMetadata(imageIndex);
if (metadata != null) {
if (metadata.isStandardMetadataFormatSupported() &&
formatName.equals
(IIOMetadataFormatImpl.standardMetadataFormatName)) {
return metadata;
}
String nativeName = metadata.getNativeMetadataFormatName();
if (nativeName != null && formatName.equals(nativeName)) {
return metadata;
}
String[] extraNames = metadata.getExtraMetadataFormatNames();
if (extraNames != null) {
for (int i = 0; i < extraNames.length; i++) {
if (formatName.equals(extraNames[i])) {
return metadata;
}
}
}
}
return null;
}
示例10: 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);
}
}
示例11: 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;
}