本文整理匯總了Java中javax.imageio.metadata.IIOMetadata.setFromTree方法的典型用法代碼示例。如果您正苦於以下問題:Java IIOMetadata.setFromTree方法的具體用法?Java IIOMetadata.setFromTree怎麽用?Java IIOMetadata.setFromTree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.imageio.metadata.IIOMetadata
的用法示例。
在下文中一共展示了IIOMetadata.setFromTree方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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);
}
示例3: 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);
}
示例4: 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);
}
}
示例5: 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);
}
}