Example usage for java.awt Graphics2D dispose

List of usage examples for java.awt Graphics2D dispose

Introduction

In this page you can find the example usage for java.awt Graphics2D 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:WeeklyReport.Sections.Bookings.java

public Image bookingsByTradelaneImage(PdfWriter writer) throws BadElementException {
    JFreeChart chart = new Bookings().bookingsByTradelaneChart();
    PdfContentByte contentByte = writer.getDirectContent();
    PdfTemplate template = contentByte.createTemplate(600f, 400f);
    Graphics2D graphics2d = template.createGraphics(600f, 400f, new DefaultFontMapper());
    Rectangle2D rectangle2d = new Rectangle2D.Float(10f, 0, 500f, 400f);
    chart.draw(graphics2d, rectangle2d);
    graphics2d.dispose();

    Image chartImage = Image.getInstance(template);
    return chartImage;
}

From source file:Main.java

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g.create();

    int xPos = (getWidth() - bg.getWidth()) / 2;
    int yPos = yOffset;

    yPos = yOffset;/*from  w w  w  .  ja  va  2 s .c o  m*/
    while (yPos < getHeight()) {
        g2d.drawImage(bg, xPos, yPos, this);
        yPos += bg.getHeight();
    }

    g2d.dispose();
}

From source file:$.SayHiImage.java

private void writeImage(OutputStream out) throws IOException {
        BufferedImage img = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = img.createGraphics();

        g2d.setPaint(Color.red);//www  . j av a  2  s.  c o m
        g2d.setFont(new Font("Serif", Font.BOLD, 36));
        g2d.drawString("Hi there, how are you doing today?", 5, g2d.getFontMetrics().getHeight());
        g2d.dispose();

        ImageIO.write(img, "jpg", out);
    }

From source file:ClipImage.java

public void paint(Graphics g) {

    w = getWidth();/*  www  .j a v a2s  .  c om*/
    h = getHeight();

    if (w <= 0 || h <= 0)
        return;

    Graphics2D g2 = createDemoGraphics2D(g);
    drawDemo(g2);
    g2.dispose();

    if (offImg != null && isShowing()) {
        g.drawImage(offImg, 0, 0, this);
    }

    newBufferedImage = false;
}

From source file:net.rptools.maptool.util.PersistenceUtil.java

public static void saveToken(Token token, File file, boolean doWait) throws IOException {
    // Thumbnail/*from www . ja  v a  2  s.  c  o  m*/
    BufferedImage image = null;
    if (doWait)
        image = ImageManager.getImageAndWait(token.getImageAssetId());
    else
        image = ImageManager.getImage(token.getImageAssetId());

    Dimension sz = new Dimension(image.getWidth(), image.getHeight());
    SwingUtil.constrainTo(sz, 50);
    BufferedImage thumb = new BufferedImage(sz.width, sz.height, BufferedImage.TRANSLUCENT);
    Graphics2D g = thumb.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawImage(image, 0, 0, sz.width, sz.height, null);
    g.dispose();

    PackedFile pakFile = null;
    try {
        pakFile = new PackedFile(file);
        saveAssets(token.getAllImageAssets(), pakFile);
        pakFile.putFile(Token.FILE_THUMBNAIL, ImageUtil.imageToBytes(thumb, "png"));
        pakFile.setContent(token);
        pakFile.setProperty(PROP_VERSION, MapTool.getVersion());
        pakFile.save();
    } finally {
        if (pakFile != null)
            pakFile.close();
    }
}

From source file:IDlook.java

private void createThumbnail() {
    int maxDim = 350;
    try {//from   www.  jav a 2s .c  o m
        Image inImage = icon.getImage();

        double scale = (double) maxDim / (double) inImage.getHeight(null);
        if (inImage.getWidth(null) > inImage.getHeight(null)) {
            scale = (double) maxDim / (double) inImage.getWidth(null);
        }

        int scaledW = (int) (scale * inImage.getWidth(null));
        int scaledH = (int) (scale * inImage.getHeight(null));

        BufferedImage outImage = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_INT_RGB);

        AffineTransform tx = new AffineTransform();

        if (scale < 1.0d) {
            tx.scale(scale, scale);
        }

        Graphics2D g2d = outImage.createGraphics();
        g2d.drawImage(inImage, tx, null);
        g2d.dispose();

        iconThumbnail = new ImageIcon(outImage);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:WeeklyReport.Sections.Commodities.java

public Image commodityChartImage(PdfWriter writer) throws BadElementException {
    JFreeChart chart = commodityChart();
    PdfContentByte contentByte = writer.getDirectContent();
    PdfTemplate template = contentByte.createTemplate(525f, 475f);
    Graphics2D graphics2d = template.createGraphics(525f, 475f, new DefaultFontMapper());
    Rectangle2D rectangle2d = new Rectangle2D.Float(0, 0, 525f, 475f);
    chart.draw(graphics2d, rectangle2d);
    graphics2d.dispose();

    Image chartImage = Image.getInstance(template);
    return chartImage;
}

From source file:com.anevis.jfreechartsamplespring.chart.ChartServiceImpl.java

private byte[] writeChartsToDocument(JFreeChart... charts) {
    try {/* ww w . j  a v  a 2s  .  co m*/
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        float width = PageSize.A4.getWidth();
        float height = PageSize.A4.getHeight() / 2;
        int index = 0;

        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        document.open();
        PdfContentByte contentByte = writer.getDirectContent();

        for (JFreeChart chart : charts) {

            PdfTemplate template = contentByte.createTemplate(width, height);
            Graphics2D graphics2D = template.createGraphics(width, height);
            Rectangle2D rectangle2D = new Rectangle2D.Double(0, 0, width, height);

            chart.draw(graphics2D, rectangle2D);

            graphics2D.dispose();
            contentByte.addTemplate(template, 0, height - (height * index));
            index++;
        }

        writer.flush();
        document.close();

        return baos.toByteArray();
    } catch (DocumentException ex) {
        Logger.getLogger(ChartService.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:Wallpaper.java

@Override
public void paint(Graphics g, JComponent c) {
    super.paint(g, c);

    Graphics2D g2 = (Graphics2D) g.create();

    int w = c.getWidth();
    int h = c.getHeight();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f));
    g2.setPaint(new GradientPaint(0, 0, Color.yellow, 0, h, Color.red));
    g2.fillRect(0, 0, w, h);/*from  w w  w . j a v a  2  s . c  om*/

    g2.dispose();
}

From source file:com.igormaznitsa.jhexed.renders.svg.SVGImage.java

public BufferedImage rasterize(final int imageType) throws IOException {
    final int svgWidth = Math.round(getSVGWidth());
    final int svgHeight = Math.round(getSVGHeight());

    final BufferedImage result = new BufferedImage(svgWidth, svgHeight, imageType);
    final Graphics2D g = result.createGraphics();

    processAntialias(this.quality, g);
    this.svgGraphicsNode.primitivePaint(g);

    g.dispose();
    return result;
}