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;
}
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;
}
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);
}
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);
}
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);
}
}
Aggregations