use of java.awt.image.BufferedImage in project antlr4 by antlr.
the class TreeViewer method generatePNGFile.
private static void generatePNGFile(TreeViewer viewer, JFrame dialog) {
BufferedImage bi = new BufferedImage(viewer.getSize().width, viewer.getSize().height, BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.createGraphics();
viewer.paint(g);
g.dispose();
try {
File suggestedFile = generateNonExistingPngFile();
JFileChooser fileChooser = new JFileChooserConfirmOverwrite();
fileChooser.setCurrentDirectory(suggestedFile.getParentFile());
fileChooser.setSelectedFile(suggestedFile);
FileFilter pngFilter = new FileFilter() {
@Override
public boolean accept(File pathname) {
if (pathname.isFile()) {
return pathname.getName().toLowerCase().endsWith(".png");
}
return true;
}
@Override
public String getDescription() {
return "PNG Files (*.png)";
}
};
fileChooser.addChoosableFileFilter(pngFilter);
fileChooser.setFileFilter(pngFilter);
int returnValue = fileChooser.showSaveDialog(dialog);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File pngFile = fileChooser.getSelectedFile();
ImageIO.write(bi, "png", pngFile);
try {
// Try to open the parent folder using the OS' native file manager.
Desktop.getDesktop().open(pngFile.getParentFile());
} catch (Exception ex) {
// We could not launch the file manager: just show a popup that we
// succeeded in saving the PNG file.
JOptionPane.showMessageDialog(dialog, "Saved PNG to: " + pngFile.getAbsolutePath());
ex.printStackTrace();
}
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(dialog, "Could not export to PNG: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
}
}
use of java.awt.image.BufferedImage in project javatari by ppeccin.
the class JComboBoxNim method loadImages.
private void loadImages() {
try {
BufferedImage image = SwingHelper.loadAsCompatibleTranslucentImage("org/javatari/pc/room/settings/images/Joystick.png");
joystickIcon = new ImageIcon(image);
joystickIconGrayed = new ImageIcon(GrayFilter.createDisabledImage(image));
image = SwingHelper.loadAsCompatibleTranslucentImage("org/javatari/pc/room/settings/images/Paddle.png");
paddleIcon = new ImageIcon(image);
paddleIconGrayed = new ImageIcon(GrayFilter.createDisabledImage(image));
} catch (IOException ex) {
System.out.println("SettingsDialog: unable to load images\n" + ex);
}
}
use of java.awt.image.BufferedImage in project javatari by ppeccin.
the class SwingHelper method asCompatibleImage.
public static BufferedImage asCompatibleImage(Image img) {
BufferedImage ret = defaultScreenDeviceConfiguration().createCompatibleImage(img.getWidth(null), img.getHeight(null));
Graphics2D gc = ret.createGraphics();
gc.drawImage(img, 0, 0, null);
gc.dispose();
return ret;
}
use of java.awt.image.BufferedImage in project javatari by ppeccin.
the class SwingHelper method asCompatibleImage.
public static BufferedImage asCompatibleImage(Image img, int transparency) {
BufferedImage ret = defaultScreenDeviceConfiguration().createCompatibleImage(img.getWidth(null), img.getHeight(null), transparency);
Graphics2D gc = ret.createGraphics();
gc.setComposite(AlphaComposite.Src);
gc.drawImage(img, 0, 0, null);
gc.dispose();
return ret;
}
use of java.awt.image.BufferedImage in project antlrworks by antlr.
the class SDGenerator method renderRuleToBitmapFile.
public void renderRuleToBitmapFile(String ruleName, String imageFormat, String file) throws Exception {
GGraph graph = createGraph(ruleName);
int width = (int) (graph.getWidth() + 1);
int height = (int) (graph.getHeight() + 1);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g2d = (Graphics2D) image.getGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
context.setEngine(new GEngineGraphics());
context.setGraphics2D(g2d);
g2d.setColor(Color.white);
g2d.fillRect(0, 0, width, height);
graph.draw();
g2d.dispose();
ImageIO.write(image, imageFormat, new File(file));
}
Aggregations