Java BufferedImage Show show(final BufferedImage image, final int width, final int height)

Here you can find the source of show(final BufferedImage image, final int width, final int height)

Description

show

License

Apache License

Declaration

public static void show(final BufferedImage image, final int width, final int height) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.BorderLayout;

import java.awt.Graphics;

import java.awt.image.BufferedImage;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

public class Main {
    public static void show(final BufferedImage image, String title) {
        show(image, image.getWidth() + 100, image.getHeight() + 100, title);
    }/*  w w  w. j  a  va2s.  com*/

    public static void show(final BufferedImage image) {
        show(image, image.getWidth() + 100, image.getHeight() + 100);
    }

    public static void show(final BufferedImage image, final int width, final int height) {
        show(image, width, height, "");
    }

    public static void show(final BufferedImage image, final int width, final int height, final String title) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            @SuppressWarnings("serial")
            public void run() {
                new JFrame() {
                    {
                        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                        setTitle(title);
                        setSize(width, height);
                        setVisible(true);
                        getContentPane().setLayout(new BorderLayout());

                        final JPanel panel = new JPanel() {
                            @Override
                            public void paintComponent(Graphics g) {
                                super.paintComponent(g);
                                g.drawImage(image, 50, 50, null);
                            }

                        };

                        getContentPane().add(panel, BorderLayout.CENTER);
                    }

                };
            }
        });
    }
}

Related

  1. printImage(BufferedImage im, String title)
  2. printImageFromComponents(final Component _rootComponent, final int _currentColumn, final BufferedImage _bi)
  3. showBufferedImage(BufferedImage I)
  4. showImage(BufferedImage im)
  5. showImage(BufferedImage image, String title, boolean fitToScreen)
  6. showImage(BufferedImage img)