Search in sources :

Example 66 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project ChatGameFontificator by GlitchCog.

the class ControlWindow method saveScreenshot.

/**
 * Takes and saves a screenshot of the current chat window
 *
 * @return whether the screenshot was saved
 */
private boolean saveScreenshot() {
    // Take the screenshot before the save file chooser is shown
    ChatPanel chat = chatWindow.getChatPanel();
    BufferedImage chatImage = new BufferedImage(chat.getWidth(), chat.getHeight(), screenshotOptions.isTransparencyEnabled() ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB);
    Graphics chatGraphics = chatImage.getGraphics();
    chat.paint(chatGraphics);
    final boolean chromaEnabled = Boolean.toString(true).equalsIgnoreCase(fProps.getProperty(FontificatorProperties.KEY_CHAT_CHROMA_ENABLED));
    if (screenshotOptions.isTransparencyEnabled() && chromaEnabled) {
        final int chromaKey = new Color(Integer.parseInt(fProps.getProperty(FontificatorProperties.KEY_COLOR_CHROMA_KEY), 16)).getRGB();
        final int transparentPixel = new Color(0, true).getRGB();
        for (int r = 0; r < chatImage.getHeight(); r++) {
            for (int c = 0; c < chatImage.getWidth(); c++) {
                if (chatImage.getRGB(c, r) == chromaKey) {
                    chatImage.setRGB(c, r, transparentPixel);
                }
            }
        }
    }
    File saveFile = getTargetSaveFile(screenshotSaver, DEFAULT_SCREENSHOT_FILE_EXTENSION);
    if (saveFile != null) {
        try {
            if (screenshotOptions.isMetadataEnabled()) {
                ImageWriter writer = ImageIO.getImageWritersByFormatName("PNG").next();
                ImageOutputStream stream = ImageIO.createImageOutputStream(saveFile);
                writer.setOutput(stream);
                IIOMetadata metadata = writer.getDefaultImageMetadata(ImageTypeSpecifier.createFromRenderedImage(chatImage), writer.getDefaultWriteParam());
                IIOMetadataNode title = generateMetadataNode("Title", "CGF Screenshot");
                IIOMetadataNode software = generateMetadataNode("Software", "Chat Game Fontificator");
                final String fontGameName = ControlPanelFont.getFontGameName(fProps.getProperty(FontificatorProperties.KEY_FONT_FILE_FONT));
                final String borderGameName = ControlPanelFont.getBorderGameName(fProps.getProperty(FontificatorProperties.KEY_FONT_FILE_BORDER));
                IIOMetadataNode description = generateMetadataNode("Description", fontGameName + " Font / " + borderGameName + " Border");
                IIOMetadataNode text = new IIOMetadataNode("tEXt");
                text.appendChild(title);
                text.appendChild(software);
                text.appendChild(description);
                final String metadataFormatStr = "javax_imageio_png_1.0";
                IIOMetadataNode root = new IIOMetadataNode(metadataFormatStr);
                root.appendChild(text);
                metadata.mergeTree(metadataFormatStr, root);
                writer.write(metadata, new IIOImage(chatImage, null, metadata), writer.getDefaultWriteParam());
                stream.close();
            } else {
                ImageIO.write(chatImage, "png", saveFile);
            }
            return true;
        } catch (Exception e) {
            logger.error("Unable to save screenshot", e);
            return false;
        }
    }
    return false;
}
Also used : Color(java.awt.Color) ImageWriter(javax.imageio.ImageWriter) ChatPanel(com.glitchcog.fontificator.gui.chat.ChatPanel) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) IIOImage(javax.imageio.IIOImage) Graphics(java.awt.Graphics) IIOMetadata(javax.imageio.metadata.IIOMetadata) File(java.io.File) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) ImageOutputStream(javax.imageio.stream.ImageOutputStream)

Example 67 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project java-swing-tips by aterai.

the class MainPanel method createAnimatedGifFile.

private static File createAnimatedGifFile(List<Shape> list, Dimension size) throws IOException {
    Iterator<ImageWriter> it = ImageIO.getImageWritersByFormatName("gif");
    ImageWriter writer = it.hasNext() ? it.next() : null;
    if (Objects.isNull(writer)) {
        throw new IOException();
    }
    File file = File.createTempFile("anime", ".gif");
    file.deleteOnExit();
    try (ImageOutputStream stream = ImageIO.createImageOutputStream(file)) {
        writer.setOutput(stream);
        writer.prepareWriteSequence(null);
        IIOMetadataNode gce = new IIOMetadataNode("GraphicControlExtension");
        gce.setAttribute("disposalMethod", "none");
        gce.setAttribute("userInputFlag", "FALSE");
        gce.setAttribute("transparentColorFlag", "FALSE");
        gce.setAttribute("transparentColorIndex", "0");
        gce.setAttribute("delayTime", Objects.toString(DELAY));
        IIOMetadataNode ae = new IIOMetadataNode("ApplicationExtension");
        ae.setAttribute("applicationID", "NETSCAPE");
        ae.setAttribute("authenticationCode", "2.0");
        // last two bytes is an unsigned short (little endian) that
        // indicates the number of times to loop.
        // 0 means loop forever.
        ae.setUserObject(new byte[] { 0x1, 0x0, 0x0 });
        IIOMetadataNode aes = new IIOMetadataNode("ApplicationExtensions");
        aes.appendChild(ae);
        // Create animated GIF using imageio | Oracle Community
        // https://community.oracle.com/thread/1264385
        BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
        ImageWriteParam iwp = writer.getDefaultWriteParam();
        IIOMetadata metadata = writer.getDefaultImageMetadata(new ImageTypeSpecifier(image), iwp);
        String metaFormat = metadata.getNativeMetadataFormatName();
        Node root = metadata.getAsTree(metaFormat);
        root.appendChild(gce);
        root.appendChild(aes);
        metadata.setFromTree(metaFormat, root);
        // make frame
        for (int i = 0; i < list.size() * DELAY; i++) {
            paintFrame(image, list);
            Collections.rotate(list, 1);
            writeToSequence(writer, image, metadata);
            metadata = null;
        }
        writer.endWriteSequence();
    }
    return file;
}
Also used : IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Node(org.w3c.dom.Node) ImageWriter(javax.imageio.ImageWriter) IOException(java.io.IOException) ImageWriteParam(javax.imageio.ImageWriteParam) BufferedImage(java.awt.image.BufferedImage) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) IIOMetadata(javax.imageio.metadata.IIOMetadata) File(java.io.File) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) ImageOutputStream(javax.imageio.stream.ImageOutputStream)

Example 68 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project android by JetBrains.

the class UniqueParameterTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    loadProject(PROJECT_WITH_APPAND_LIB);
    assertNotNull(myAndroidFacet);
    AndroidModel androidModel = AndroidModuleModel.get(myAndroidFacet);
    assertNotNull(androidModel);
    // Set up modules
    for (Module m : ModuleManager.getInstance(getProject()).getModules()) {
        if (m.getName().equals("app")) {
            myAppModule = m;
            break;
        }
    }
    assertNotNull(myAppModule);
    myAppFacet = AndroidFacet.getInstance(myAppModule);
    assertNotNull(myAppFacet);
    addLatestAndroidSdk(myAppModule);
    assertNotNull(AndroidPlatform.getInstance(myAppModule));
    assertNotNull(myAppFacet.getAndroidModel());
    // TODO: b/23032990
    ProductFlavorContainer paidFlavor = AndroidModuleModel.get(myAppFacet).findProductFlavor("paid");
    assertNotNull(paidFlavor);
    myPaidSourceProvider = paidFlavor.getSourceProvider();
    assertNotNull(myPaidSourceProvider);
    myMainSourceProvider = myAppFacet.getMainSourceProvider();
    assertNotNull(myMainSourceProvider);
    TemplateMetadata mockMetadata = Mockito.mock(TemplateMetadata.class);
    Element elem = new IIOMetadataNode();
    elem.setAttribute(ATTR_TYPE, Parameter.Type.STRING.toString());
    elem.setAttribute(ATTR_ID, "testParam");
    elem.setAttribute(ATTR_DEFAULT, "");
    elem.setAttribute(ATTR_SUGGEST, null);
    elem.setAttribute(ATTR_NAME, "Test Param");
    elem.setAttribute(ATTR_HELP, "This is a test parameter");
    elem.setAttribute(ATTR_CONSTRAINTS, "");
    myParameter = new Parameter(mockMetadata, elem);
}
Also used : ProductFlavorContainer(com.android.builder.model.ProductFlavorContainer) AndroidModel(com.android.tools.idea.model.AndroidModel) Element(org.w3c.dom.Element) Module(com.intellij.openapi.module.Module) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Example 69 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project android by JetBrains.

the class ParameterTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    TemplateMetadata mockMetadata = Mockito.mock(TemplateMetadata.class);
    Element elem = new IIOMetadataNode();
    elem.setAttribute(ATTR_TYPE, Parameter.Type.STRING.toString());
    elem.setAttribute(ATTR_ID, "testParam");
    elem.setAttribute(ATTR_DEFAULT, "");
    elem.setAttribute(ATTR_SUGGEST, null);
    elem.setAttribute(ATTR_NAME, "Test Param");
    elem.setAttribute(ATTR_HELP, "This is a test parameter");
    elem.setAttribute(ATTR_CONSTRAINTS, "");
    myParameter = new Parameter(mockMetadata, elem);
}
Also used : Element(org.w3c.dom.Element) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Example 70 with IIOMetadataNode

use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.

the class ITXtTest method readFrom.

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);
    }
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) ImageInputStream(javax.imageio.stream.ImageInputStream) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Node(org.w3c.dom.Node) ImageReader(javax.imageio.ImageReader) IIOImage(javax.imageio.IIOImage)

Aggregations

IIOMetadataNode (javax.imageio.metadata.IIOMetadataNode)132 Node (org.w3c.dom.Node)20 IIOMetadata (javax.imageio.metadata.IIOMetadata)12 NodeList (org.w3c.dom.NodeList)12 TIFFField (it.geosolutions.imageio.plugins.tiff.TIFFField)10 Iterator (java.util.Iterator)9 BufferedImage (java.awt.image.BufferedImage)8 ArrayList (java.util.ArrayList)8 ASOCBoxMetadataNode (it.geosolutions.imageio.plugins.jp2k.box.ASOCBoxMetadataNode)5 UUIDBoxMetadataNode (it.geosolutions.imageio.plugins.jp2k.box.UUIDBoxMetadataNode)5 XMLBoxMetadataNode (it.geosolutions.imageio.plugins.jp2k.box.XMLBoxMetadataNode)5 IOException (java.io.IOException)5 ImageOutputStream (javax.imageio.stream.ImageOutputStream)5 File (java.io.File)4 IIOImage (javax.imageio.IIOImage)4 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)4 ImageWriter (javax.imageio.ImageWriter)4 TIFFTag (it.geosolutions.imageio.plugins.tiff.TIFFTag)3 Color (java.awt.Color)3 Point (java.awt.Point)3