Search in sources :

Example 36 with BufferedImage

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();
    }
}
Also used : BufferedImage(java.awt.image.BufferedImage) GGraphGroup(org.antlr.works.visualization.graphics.graph.GGraphGroup)

Example 37 with BufferedImage

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);
    }
}
Also used : Dimension(java.awt.Dimension) IOException(java.io.IOException) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 38 with BufferedImage

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) {
            }
        }
    }
}
Also used : OutputStream(java.io.OutputStream) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage)

Example 39 with BufferedImage

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());
    }
}
Also used : JFrame(javax.swing.JFrame) Toolkit(java.awt.Toolkit) Point(java.awt.Point) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) Cursor(java.awt.Cursor) BufferedImage(java.awt.image.BufferedImage)

Example 40 with BufferedImage

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");
}
Also used : Graphics(java.awt.Graphics) IntArray(com.badlogic.gdx.utils.IntArray) Vector2(com.badlogic.gdx.math.Vector2) TiledMapTileSet(com.badlogic.gdx.maps.tiled.TiledMapTileSet) TexturePacker(com.badlogic.gdx.tools.texturepacker.TexturePacker) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Aggregations

BufferedImage (java.awt.image.BufferedImage)1702 Graphics2D (java.awt.Graphics2D)376 IOException (java.io.IOException)220 File (java.io.File)195 FunctionException (lucee.runtime.exp.FunctionException)122 Graphics (java.awt.Graphics)104 ByteArrayOutputStream (java.io.ByteArrayOutputStream)89 Color (java.awt.Color)88 ByteArrayInputStream (java.io.ByteArrayInputStream)86 Test (org.junit.Test)81 WritableRaster (java.awt.image.WritableRaster)75 Point (java.awt.Point)71 Rectangle (java.awt.Rectangle)68 AffineTransform (java.awt.geom.AffineTransform)57 Image (java.awt.Image)56 InputStream (java.io.InputStream)51 Dimension (java.awt.Dimension)50 ImageIcon (javax.swing.ImageIcon)50 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)46 ImageWriter (javax.imageio.ImageWriter)45