Example usage for java.awt Graphics dispose

List of usage examples for java.awt Graphics dispose

Introduction

In this page you can find the example usage for java.awt Graphics dispose.

Prototype

public abstract void dispose();

Source Link

Document

Disposes of this graphics context and releases any system resources that it is using.

Usage

From source file:ImageOpByRomain.java

/**
 * <p>//from www.ja  v  a2 s.com
 * Return a new compatible image that contains a copy of the specified image.
 * This method ensures an image is compatible with the hardware, and therefore
 * optimized for fast blitting operations.
 * </p>
 * 
 * @see #createCompatibleImage(java.awt.image.BufferedImage)
 * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
 * @see #createCompatibleImage(int, int)
 * @see #createTranslucentCompatibleImage(int, int)
 * @see #loadCompatibleImage(java.net.URL)
 * @param image
 *            the image to copy into a new compatible image
 * @return a new compatible copy, with the same width and height and
 *         transparency and content, of <code>image</code>
 */
public static BufferedImage toCompatibleImage(BufferedImage image) {
    if (image.getColorModel().equals(CONFIGURATION.getColorModel())) {
        return image;
    }

    BufferedImage compatibleImage = CONFIGURATION.createCompatibleImage(image.getWidth(), image.getHeight(),
            image.getTransparency());
    Graphics g = compatibleImage.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return compatibleImage;
}

From source file:ImageFlip.java

public void paint(Graphics g) {
    Image myImage = new ImageIcon("yourImage.jpg").getImage();
    BufferedImage bufferedImage = new BufferedImage(myImage.getWidth(null), myImage.getHeight(null),
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = (Graphics2D) g;

    Graphics gb = bufferedImage.getGraphics();
    gb.drawImage(myImage, 0, 0, null);/* w w  w .j a v a  2s  . co  m*/
    gb.dispose();

    AffineTransform tx = AffineTransform.getScaleInstance(-1, 1);
    tx.translate(-myImage.getWidth(null), 0);
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    bufferedImage = op.filter(bufferedImage, null);

    g2d.drawImage(myImage, 10, 10, null);
    g2d.drawImage(bufferedImage, null, 300, 10);
}

From source file:Main.java

public void add(int dx, int dy) {
    endPoint.x += dx;// www . j  a  v  a2 s  .  c  o  m
    endPoint.y += dy;
    Graphics g = getGraphics();
    g.drawLine(startPoint.x, startPoint.y, endPoint.x, endPoint.y);
    g.dispose();
    startPoint.x = endPoint.x;
    startPoint.y = endPoint.y;
}

From source file:ImageBorderHack.java

public BufferedImage createBufferedImage(Image img) {
    BufferedImage buff = new BufferedImage(img.getWidth(null), img.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);
    Graphics gfx = buff.createGraphics();
    gfx.drawImage(img, 0, 0, null);/*from  w w w .j a  v a2 s  .  c  om*/
    gfx.dispose();
    return buff;
}

From source file:Main.java

public void paint(Graphics g) {
    g.setColor(Color.red);/*from  w  w  w .  j a v a 2  s  .c om*/
    Graphics clippedGraphics = g.create();
    clippedGraphics.drawRect(0, 0, 100, 100);
    clippedGraphics.clipRect(25, 25, 50, 50);
    clippedGraphics.drawLine(0, 0, 100, 100);
    clippedGraphics.dispose();
    clippedGraphics = null;
    g.drawLine(0, 100, 100, 0);
}

From source file:Main.java

public void actionPerformed(ActionEvent evt) {
    Graphics g = getGraphics();
    Point p = getClick();//www  . j  a v  a2  s .c  o m
    g.drawOval(p.x - 2, p.y - 2, 4, 4);
    Point q = getClick();
    g.drawOval(q.x - 2, q.y - 2, 4, 4);
    g.drawLine(p.x, p.y, q.x, q.y);
    g.dispose();
}

From source file:org.jcurl.mr.gui.MouseSketchPanel.java

public void keyPressed(final KeyEvent e) {
    if (e.getKeyChar() == hotKey) {
        log.debug("HotKey pressed");
        isHot = true;// www. j a  va 2  s  .c  o m
    }
    switch (e.getKeyCode()) {
    case KeyEvent.VK_ESCAPE:
        current = null;
        curve.clear();
        this.repaint();
        break;
    case KeyEvent.VK_F1:
        final Graphics g = getGraphics();
        paint(g, PointList.getLine(curve));
        g.dispose();
        break;
    }
}

From source file:org.jcurl.mr.exp.gui.MouseSketchPanel.java

private void lineTo(final Point p) {
    if (current != null) {
        log.debug("draw line");
        final Graphics g = getGraphics();
        g.drawLine(current.x, current.y, p.x, p.y);
        g.dispose();
    }//from   w ww. j  a  v a  2  s .c  om
    curve.add(current = p);
}

From source file:org.jcurl.mr.exp.gui.MouseSketchPanel.java

public void keyPressed(KeyEvent e) {
    if (e.getKeyChar() == hotKey) {
        log.debug("HotKey pressed");
        isHot = true;// w  ww  . java2  s  . c o m
    }
    switch (e.getKeyCode()) {
    case KeyEvent.VK_ESCAPE:
        this.current = null;
        this.curve.clear();
        this.repaint();
        break;
    case KeyEvent.VK_F1:
        final Graphics g = getGraphics();
        paint(g, PointList.getLine(curve));
        g.dispose();
        break;
    }
}

From source file:org.jcurl.demo.tactics.JCurlShotPlanner.java

private static void renderPng(final Container src, final File dst) throws IOException {
    final BufferedImage img = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB);
    final Graphics g = img.getGraphics();
    try {//from www .  j a va2 s . c om
        // SwingUtilities.paintComponent(g, src, src.getBounds(), null);
        src.paintAll(g);
    } finally {
        g.dispose();
    }
    ImageIO.write(img, "png", dst);
}