Java BufferedImage Show showImage(BufferedImage img)

Here you can find the source of showImage(BufferedImage img)

Description

Show image in window

License

Open Source License

Parameter

Parameter Description
img a parameter

Declaration

public static void showImage(BufferedImage img) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

public class Main {
    /**/*from   ww w  .  j av  a2 s  .  c om*/
     * Show image in window
     *
     * @param img
     */
    public static void showImage(BufferedImage img) {
        showImage("", img);
    }

    /**
     * Show image in windwos, with specified title
     *
     * @param title
     * @param img
     */
    public static void showImage(String title, BufferedImage img) {

        SwingUtilities.invokeLater(() -> {

            JFrame frame = new JFrame();
            frame.setTitle(title + " " + img.toString());

            // create label for image, with border
            JLabel lbl = new JLabel(new ImageIcon(img));
            lbl.setBorder(BorderFactory.createLineBorder(Color.blue));

            JPanel content = new JPanel();
            content.add(lbl);

            frame.setContentPane(content);

            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        });

    }
}

Related

  1. printImageFromComponents(final Component _rootComponent, final int _currentColumn, final BufferedImage _bi)
  2. show(final BufferedImage image, final int width, final int height)
  3. showBufferedImage(BufferedImage I)
  4. showImage(BufferedImage im)
  5. showImage(BufferedImage image, String title, boolean fitToScreen)
  6. showImage(BufferedImage img)
  7. showImage(final BufferedImage img, final HashMap inputHandles, final HashMap outputHandles)
  8. showImage(String title, BufferedImage image)
  9. showImageLabel(BufferedImage imagen, JLabel jLabel, JComponent jc)