use of java.awt.image.BufferedImage in project antlrworks by antlr.
the class GView method paintComponent.
public void paintComponent(Graphics g) {
super.paintComponent(g);
ATEUtilities.prepareForText(g);
if (!canDraw()) {
paintPlaceholder(g);
return;
}
int width = getPaintWidth();
int height = getPaintHeight();
if (useCachedImage) {
boolean sizeChanged = cachedImage != null && (cachedImage.getWidth() != width || cachedImage.getHeight() != height);
if (sizeChanged) {
// instead of re-creating a new one (useful for fast live resize).
if (!cachedImageResize && cachedImage != null) {
cachedImage.flush();
cachedImage = null;
}
}
if (cachedImage == null) {
// Create a new cache image.
cachedImage = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D gCache = (Graphics2D) cachedImage.getGraphics();
ATEUtilities.prepareForText(gCache);
gCache.setColor(Color.white);
gCache.fillRect(0, 0, width, height);
render(gCache);
gCache.dispose();
} else if (cachedImageRerender) {
// Only render the cachedImage without re-creating it again
Graphics2D gCache = (Graphics2D) cachedImage.getGraphics();
ATEUtilities.prepareForText(gCache);
gCache.setColor(Color.white);
gCache.fillRect(0, 0, width, height);
render(gCache);
gCache.dispose();
cachedImageRerender = false;
}
}
if (cachedImage == null)
render((Graphics2D) g);
else
g.drawImage(cachedImage, 0, 0, width, height, null);
if (!cachedImageResize && getCurrentGraph() instanceof GGraphGroup) {
// Draw the selected segment of a path (and only if we are not resizing using only the cached image)
Graphics2D g2d = (Graphics2D) g;
context.offsetX = offset_x;
context.offsetY = offset_y;
context.setGraphics2D(g2d);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
getCurrentPathGroup().drawSelectedElement();
}
}
use of java.awt.image.BufferedImage in project CoreNLP by stanfordnlp.
the class DisplayMatchesPanel method doExportTree.
private void doExportTree() {
JFileChooser chooser = new JFileChooser();
chooser.setSelectedFile(new File("./tree.png"));
FileNameExtensionFilter filter = new FileNameExtensionFilter("PNG images", "png");
chooser.setFileFilter(filter);
int status = chooser.showSaveDialog(this);
if (status != JFileChooser.APPROVE_OPTION)
return;
Dimension size = tjp.getPreferredSize();
BufferedImage im = new BufferedImage((int) size.getWidth(), (int) size.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = im.createGraphics();
tjp.paint(g);
try {
ImageIO.write(im, "png", chooser.getSelectedFile());
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Failed to save the tree image file.\n" + e.getLocalizedMessage(), "Export Error", JOptionPane.ERROR_MESSAGE);
}
}
use of java.awt.image.BufferedImage in project jforum2 by rafaelsteil.
the class Captcha method writeCaptchaImage.
public void writeCaptchaImage() {
BufferedImage image = SessionFacade.getUserSession().getCaptchaImage();
if (image == null) {
return;
}
OutputStream outputStream = null;
try {
outputStream = JForumExecutionContext.getResponse().getOutputStream();
ImageIO.write(image, "jpg", outputStream);
} catch (IOException ex) {
logger.error(ex);
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException ex) {
}
}
}
}
use of java.awt.image.BufferedImage in project libgdx by libgdx.
the class LwjglAWTInput method showCursor.
private void showCursor(boolean visible) {
if (!visible) {
Toolkit t = Toolkit.getDefaultToolkit();
Image i = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
Cursor noCursor = t.createCustomCursor(i, new Point(0, 0), "none");
JFrame frame = findJFrame(canvas);
frame.setCursor(noCursor);
} else {
JFrame frame = findJFrame(canvas);
frame.setCursor(Cursor.getDefaultCursor());
}
}
use of java.awt.image.BufferedImage in project libgdx by libgdx.
the class TiledMapPacker method packTilesets.
/** Traverse the specified tilesets, optionally lookup the used ids and pass every tile image to the {@link TexturePacker},
* optionally ignoring unused tile ids */
private void packTilesets(FileHandle inputDirHandle, Settings texturePackerSettings) throws IOException {
BufferedImage tile;
Vector2 tileLocation;
Graphics g;
packer = new TexturePacker(texturePackerSettings);
for (TiledMapTileSet set : tilesetsToPack.values()) {
String tilesetName = set.getName();
System.out.println("Processing tileset " + tilesetName);
IntArray usedIds = this.settings.stripUnusedTiles ? getUsedIdsBucket(tilesetName, -1) : null;
int tileWidth = set.getProperties().get("tilewidth", Integer.class);
int tileHeight = set.getProperties().get("tileheight", Integer.class);
int firstgid = set.getProperties().get("firstgid", Integer.class);
String imageName = set.getProperties().get("imagesource", String.class);
TileSetLayout layout = new TileSetLayout(firstgid, set, inputDirHandle);
for (int gid = layout.firstgid, i = 0; i < layout.numTiles; gid++, i++) {
boolean verbose = this.settings.verbose;
if (usedIds != null && !usedIds.contains(gid)) {
if (verbose) {
System.out.println("Stripped id #" + gid + " from tileset \"" + tilesetName + "\"");
}
continue;
}
tileLocation = layout.getLocation(gid);
tile = new BufferedImage(tileWidth, tileHeight, BufferedImage.TYPE_4BYTE_ABGR);
g = tile.createGraphics();
g.drawImage(layout.image, 0, 0, tileWidth, tileHeight, (int) tileLocation.x, (int) tileLocation.y, (int) tileLocation.x + tileWidth, (int) tileLocation.y + tileHeight, null);
if (verbose) {
System.out.println("Adding " + tileWidth + "x" + tileHeight + " (" + (int) tileLocation.x + ", " + (int) tileLocation.y + ")");
}
// AtlasTmxMapLoader expects every tileset's index to begin at zero for the first tile in every tileset.
// so the region's adjusted gid is (gid - layout.firstgid). firstgid will be added back in AtlasTmxMapLoader on load
int adjustedGid = gid - layout.firstgid;
final String separator = "_";
String regionName = tilesetName + separator + adjustedGid;
packer.addImage(tile, regionName);
}
}
String tilesetOutputDir = outputDir.toString() + "/" + this.settings.tilesetOutputDirectory;
File relativeTilesetOutputDir = new File(tilesetOutputDir);
File outputDirTilesets = new File(relativeTilesetOutputDir.getCanonicalPath());
outputDirTilesets.mkdirs();
packer.pack(outputDirTilesets, this.settings.atlasOutputName + ".atlas");
}
Aggregations