本文整理了Java中javax.imageio.metadata.IIOMetadataNode.getAttribute()
方法的一些代码示例,展示了IIOMetadataNode.getAttribute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IIOMetadataNode.getAttribute()
方法的具体详情如下:
包路径:javax.imageio.metadata.IIOMetadataNode
类名称:IIOMetadataNode
方法名:getAttribute
暂无
代码示例来源:origin: org.springframework.boot/spring-boot
private int getDelayTime(ImageReader reader, int imageIndex) throws IOException {
IIOMetadata metadata = reader.getImageMetadata(imageIndex);
IIOMetadataNode root = (IIOMetadataNode) metadata
.getAsTree(metadata.getNativeMetadataFormatName());
IIOMetadataNode extension = findNode(root, "GraphicControlExtension");
String attribute = (extension != null) ? extension.getAttribute("delayTime")
: null;
return (attribute != null) ? Integer.parseInt(attribute) * 10 : 0;
}
代码示例来源:origin: haraldk/TwelveMonkeys
int compOnents= Integer.parseInt(startOfFrame.getAttribute("numFrameComponents"));
int transform = Integer.parseInt(adobe.getAttribute("transform"));
int cid0 = Integer.parseInt(((IIOMetadataNode) componentSpecs.item(0)).getAttribute("componentId"));
int cid1 = Integer.parseInt(((IIOMetadataNode) componentSpecs.item(1)).getAttribute("componentId"));
int cid2 = Integer.parseInt(((IIOMetadataNode) componentSpecs.item(2)).getAttribute("componentId"));
int transform = Integer.parseInt(adobe.getAttribute("transform"));
int cid0 = Integer.parseInt(((IIOMetadataNode) componentSpecs.item(0)).getAttribute("componentId"));
int cid1 = Integer.parseInt(((IIOMetadataNode) componentSpecs.item(1)).getAttribute("componentId"));
int cid2 = Integer.parseInt(((IIOMetadataNode) componentSpecs.item(2)).getAttribute("componentId"));
int cid3 = Integer.parseInt(((IIOMetadataNode) componentSpecs.item(3)).getAttribute("componentId"));
代码示例来源:origin: haraldk/TwelveMonkeys
protected final void writeComments(final IIOMetadata metadata, final ImageWriterSpi provider) throws IOException {
// TODO: Only write creator if not already present
imageOutput.write(String.format("# CREATOR: %s %s\n", provider.getVendorName(), provider.getDescription(Locale.getDefault())).getBytes(UTF8));
// Comments from metadata
if (metadata != null && metadata.isStandardMetadataFormatSupported()) {
IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
NodeList textEntries = root.getElementsByTagName("TextEntry");
for (int i = 0; i
IIOMetadataNode textEntry = (IIOMetadataNode) textEntries.item(i);
imageOutput.write(String.format("# %s", textEntry.getAttribute("value")).getBytes(UTF8));
}
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
private void forceComponentIdInRange(final IIOMetadataNode component, final String attributeName) {
String attribute = component.getAttribute(attributeName);
if (attribute != null) {
try {
int compOnentId= Integer.parseInt(attribute);
if (componentId <0) {
// Metadata doesn't like negative component ids/specs
// We'll convert to the positive value it probably should have been
compOnentId= ((byte) componentId) & 0xff;
component.setAttribute(attributeName, String.valueOf(componentId));
}
}
catch (NumberFormatException ignore) {
if ("scanComponentSpec".equals(component.getNodeName())) {
reader.processWarningOccurred("Bad SOS component selector: " + attribute);
}
else {
reader.processWarningOccurred("Bad SOF component id: " + attribute);
}
}
}
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
Object actualUserObject = ((IIOMetadataNode) actualTree).getUserObject();
assertNotNull(String.format("%s: User object missing for <%s>", message, expectedTree.getNodeName()), actualUserObject);
assertEqualUserObjects(String.format("%s: User objects for <%s MarkerTag\"%s\"> differ", message, expectedTree.getNodeName(), ((IIOMetadataNode) expectedTree).getAttribute("MarkerTag")), expectedUserObject, actualUserObject);
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testReadUnicodeLayerName() throws IOException {
PSDImageReader imageReader = createReader();
try (ImageInputStream stream = ImageIO.createImageInputStream(getClassLoaderResource("/psd/long-layer-names.psd"))) {
imageReader.setInput(stream);
IIOMetadata metadata = imageReader.getImageMetadata(0);
IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(PSDMetadata.NATIVE_METADATA_FORMAT_NAME);
NodeList layerInfo = root.getElementsByTagName("LayerInfo");
assertEquals(1, layerInfo.getLength()); // Sanity
assertEquals("If_The_Layer_Name_Is_Really_Long_Oh_No_What_Do_I_Do", ((IIOMetadataNode) layerInfo.item(0)).getAttribute("name"));
}
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testTranscodeWithMetadataCMYKtoCMYK() throws IOException {
ImageWriter writer = createImageWriter();
ImageReader reader = ImageIO.getImageReader(writer);
ByteArrayOutputStream stream = transcode(reader, getClassLoaderResource("/jpeg/cmyk-sample-multiple-chunk-icc.jpg"), writer, ColorSpace.TYPE_CMYK);
reader.reset();
reader.setInput(new ByteArrayImageInputStream(stream.toByteArray()));
BufferedImage image = reader.read(0);
assertNotNull(image);
assertEquals(100, image.getWidth());
assertEquals(100, image.getHeight());
IIOMetadata metadata = reader.getImageMetadata(0);
IIOMetadataNode standard = (IIOMetadataNode) metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
NodeList colorSpaceType = standard.getElementsByTagName("ColorSpaceType");
assertEquals(1, colorSpaceType.getLength());
assertEquals("CMYK", ((IIOMetadataNode) colorSpaceType.item(0)).getAttribute("name"));
}
代码示例来源:origin: haraldk/TwelveMonkeys
if (csType.getAttribute("name") != null) {
chroma.appendChild(csType);
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testImageMetadata1ChannelGrayWithBogusAdobeYCC() throws IOException {
JPEGImageReader reader = createReader();
try {
// Any sample should do here
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/invalid-adobe-ycc-gray-with-metadata.jpg")));
IIOMetadata metadata = reader.getImageMetadata(0);
IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
IIOMetadataNode chroma = getSingleElementByName(root, "Chroma");
IIOMetadataNode numChannels = getSingleElementByName(chroma, "NumChannels");
assertEquals("1", numChannels.getAttribute("value"));
IIOMetadataNode colorSpaceType = getSingleElementByName(chroma, "ColorSpaceType");
assertEquals("GRAY", colorSpaceType.getAttribute("name"));
}
finally {
reader.dispose();
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
if (csType.getAttribute("name") != null) {
chroma.appendChild(csType);
代码示例来源:origin: com.github.lafa.twelvemonkeyspurejava.imageio/imageio-tiff
private boolean needsCSConversion(final int photometricInterpretation, final IIOMetadata imageMetadata) throws IOException {
if (imageMetadata == null) {
// Assume we're ok
return false;
}
IIOMetadataNode stdTree = (IIOMetadataNode) imageMetadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
NodeList csTypes = stdTree.getElementsByTagName("ColorSpaceType");
if (csTypes != null && csTypes.getLength() > 0) {
IIOMetadataNode csType = (IIOMetadataNode) csTypes.item(0);
String csName = csType.getAttribute("name");
if ("YCbCr".equals(csName) && photometricInterpretation == TIFFExtension.PHOTOMETRIC_YCBCR
|| "RGB".equals(csName) && photometricInterpretation == TIFFBaseline.PHOTOMETRIC_RGB
|| "GRAY".equals(csName) && photometricInterpretation == TIFFBaseline.PHOTOMETRIC_BLACK_IS_ZERO) {
return false;
}
else {
// CMYK, or may happen because the JPEG stream is not subsampled,
// fooling the JPEGImageReader to believe the data is RGB, while it is YCbCr
if (DEBUG) {
System.out.println("Incompatible JPEG CS/PhotometricInterpretation: " + csName + "/" + photometricInterpretation);
}
return true;
}
}
// We don't really know, assume it's ok...
return false;
}
代码示例来源:origin: org.apache.xmlgraphics/xmlgraphics-commons
private double getHorizontalPixelSize(IIOMetadata meta) {
double result = 0;
IIOMetadataNode root = (IIOMetadataNode)meta.getAsTree(STANDARD_METADATA_FORMAT);
IIOMetadataNode dim = getChildNode(root, DIMENSION);
if (dim != null) {
IIOMetadataNode horz = getChildNode(dim, HORIZONTAL_PIXEL_SIZE);
if (horz != null) {
result = Double.parseDouble(horz.getAttribute("value"));
}
}
return result;
}
代码示例来源:origin: com.twelvemonkeys.imageio/imageio-jpeg
private void forceComponentIdInRange(final IIOMetadataNode component, final String attributeName) {
String attribute = component.getAttribute(attributeName);
if (attribute != null) {
try {
int compOnentId= Integer.parseInt(attribute);
if (componentId <0) {
// Metadata doesn't like negative component ids/specs
// We'll convert to the positive value it probably should have been
compOnentId= ((byte) componentId) & 0xff;
component.setAttribute(attributeName, String.valueOf(componentId));
}
}
catch (NumberFormatException ignore) {
if ("scanComponentSpec".equals(component.getNodeName())) {
reader.processWarningOccurred("Bad SOS component selector: " + attribute);
}
else {
reader.processWarningOccurred("Bad SOF component id: " + attribute);
}
}
}
}
}
代码示例来源:origin: com.talanlabs/jlegofy
private static void toGif(String src, String dst, Double precision) throws IOException, JLegofyException {
ImageReader reader = ImageIO.getImageReadersByFormatName("gif").next();
ImageInputStream ciis = ImageIO.createImageInputStream(new File(src));
reader.setInput(ciis, false);
int noi = reader.getNumImages(true);
ImageOutputStream cios = ImageIO.createImageOutputStream(new File(dst));
GifSequenceWriter g = new GifSequenceWriter(cios, BufferedImage.TYPE_INT_RGB, 50, true);
int timeBetweenFramesMS = 50;
for (int i = 0; i
IIOMetadata metadata = reader.getImageMetadata(i);
IIOMetadataNode tree = (IIOMetadataNode) metadata.getAsTree(metadata.getNativeMetadataFormatName());
NodeList children = tree.getChildNodes();
for (int j = 0; j
if ("GraphicControlExtension".equals(nodeItem.getNodeName())) {
timeBetweenFramesMS = Integer.parseInt(nodeItem.getAttribute("delayTime")) * 10;
}
}
g.writeToSequence(new JLegofyEngine().toLegofy(image, precision), timeBetweenFramesMS);
}
cios.close();
}
}
代码示例来源:origin: com.github.lafa.twelvemonkeyspurejava.imageio/imageio-jpeg
Object actualUserObject = ((IIOMetadataNode) actualTree).getUserObject();
assertNotNull(String.format("%s: User object missing for <%s>", message, expectedTree.getNodeName()), actualUserObject);
assertEqualUserObjects(String.format("%s: User objects for <%s MarkerTag\"%s\"> differ", message, expectedTree.getNodeName(), ((IIOMetadataNode) expectedTree).getAttribute("MarkerTag")), expectedUserObject, actualUserObject);
代码示例来源:origin: stackoverflow.com
System.out.println(graphicsControlExtensionNode.getAttribute("delayTime"));
代码示例来源:origin: com.twelvemonkeys.imageio/imageio-psd
@Test
public void testReadUnicodeLayerName() throws IOException {
PSDImageReader imageReader = createReader();
try (ImageInputStream stream = ImageIO.createImageInputStream(getClassLoaderResource("/psd/long-layer-names.psd"))) {
imageReader.setInput(stream);
IIOMetadata metadata = imageReader.getImageMetadata(0);
IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(PSDMetadata.NATIVE_METADATA_FORMAT_NAME);
NodeList layerInfo = root.getElementsByTagName("LayerInfo");
assertEquals(1, layerInfo.getLength()); // Sanity
assertEquals("If_The_Layer_Name_Is_Really_Long_Oh_No_What_Do_I_Do", ((IIOMetadataNode) layerInfo.item(0)).getAttribute("name"));
}
}
}
代码示例来源:origin: com.twelvemonkeys.imageio/imageio-jpeg
@Test
public void testTranscodeWithMetadataCMYKtoCMYK() throws IOException {
ImageWriter writer = createImageWriter();
ImageReader reader = ImageIO.getImageReader(writer);
ByteArrayOutputStream stream = transcode(reader, getClassLoaderResource("/jpeg/cmyk-sample-multiple-chunk-icc.jpg"), writer, ColorSpace.TYPE_CMYK);
reader.reset();
reader.setInput(new ByteArrayImageInputStream(stream.toByteArray()));
BufferedImage image = reader.read(0);
assertNotNull(image);
assertEquals(100, image.getWidth());
assertEquals(100, image.getHeight());
IIOMetadata metadata = reader.getImageMetadata(0);
IIOMetadataNode standard = (IIOMetadataNode) metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
NodeList colorSpaceType = standard.getElementsByTagName("ColorSpaceType");
assertEquals(1, colorSpaceType.getLength());
assertEquals("CMYK", ((IIOMetadataNode) colorSpaceType.item(0)).getAttribute("name"));
}
代码示例来源:origin: com.twelvemonkeys.imageio/imageio-jpeg
@Test
public void testImageMetadata1ChannelGrayWithBogusAdobeYCC() throws IOException {
JPEGImageReader reader = createReader();
try {
// Any sample should do here
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/invalid-adobe-ycc-gray-with-metadata.jpg")));
IIOMetadata metadata = reader.getImageMetadata(0);
IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
IIOMetadataNode chroma = getSingleElementByName(root, "Chroma");
IIOMetadataNode numChannels = getSingleElementByName(chroma, "NumChannels");
assertEquals("1", numChannels.getAttribute("value"));
IIOMetadataNode colorSpaceType = getSingleElementByName(chroma, "ColorSpaceType");
assertEquals("GRAY", colorSpaceType.getAttribute("name"));
}
finally {
reader.dispose();
}
}
代码示例来源:origin: com.github.lafa.twelvemonkeyspurejava.imageio/imageio-jpeg
@Test
public void testImageMetadata1ChannelGrayWithBogusAdobeYCC() throws IOException {
JPEGImageReader reader = createReader();
try {
// Any sample should do here
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/invalid-adobe-ycc-gray-with-metadata.jpg")));
IIOMetadata metadata = reader.getImageMetadata(0);
IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
IIOMetadataNode chroma = getSingleElementByName(root, "Chroma");
IIOMetadataNode numChannels = getSingleElementByName(chroma, "NumChannels");
assertEquals("1", numChannels.getAttribute("value"));
IIOMetadataNode colorSpaceType = getSingleElementByName(chroma, "ColorSpaceType");
assertEquals("GRAY", colorSpaceType.getAttribute("name"));
}
finally {
reader.dispose();
}
}