Java Utililty Methods Image Create

List of utility methods to do Image Create

Description

The list of methods to do Image Create are organized into topic(s).

Method

JPanelcreateImagePanel(Image image, Color backColor)
create Image Panel
JPanel panel = new JPanel();
panel.add(new JLabel(new ImageIcon(image)));
if (backColor != null) {
    panel.setBackground(backColor);
return panel;
ImagegetImage(Class clazz, String path)
get Image
return getIcon(clazz, path).getImage();
ImagegetImage(Component component)
Get the screen image from the component
RepaintManager repaintManager = RepaintManager.currentManager(component);
double w = component.getWidth();
double h = component.getHeight();
if ((w == 0) || (h == 0)) {
    return null;
BufferedImage image = new BufferedImage((int) w, (int) h, BufferedImage.TYPE_INT_ARGB);
repaintManager.setDoubleBufferingEnabled(false);
...
BufferedImagegetImage(Component component)
get Image
if (component == null) {
    return null;
int width = component.getWidth();
int height = component.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
component.paintAll(g);
...
BufferedImagegetImage(File imageFile)
get Image
BufferedImage al = null;
try {
    String imageFileName = imageFile.getName();
    String imageFormat = imageFileName.substring(imageFileName.lastIndexOf('.') + 1);
    Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(imageFormat);
    ImageReader reader = readers.next();
    if (reader == null) {
        JOptionPane.showConfirmDialog(null,
...
BufferedImagegetImage(final int width, final int height)
Creates an image of specified dimension, filled with the background color.
return getImage(width, height, getColorBackground());
ImagegetImage(final String name)
get Image
final ImageIcon icon = images.get(name);
if (icon == null) {
    try {
        final ImageIcon image = new ImageIcon(ImageIO.read(new File(name)));
        images.put(name, image);
        return image.getImage();
    } catch (Exception e) {
        return null;
...
ImagegetImage(ImageIcon imageIcon)
get Image
return imageIcon != null ? imageIcon.getImage() : null;
BufferedImagegetImage(JComponent component)
draw the component as an image
BufferedImage ret = new BufferedImage(component.getWidth(), component.getHeight(),
        BufferedImage.TYPE_INT_RGB);
Graphics g = ret.getGraphics();
component.paint(g);
g.dispose();
return ret;
ImagegetImage(Object obj, String filePath)
get Image
URL url = obj.getClass().getResource(filePath);
return getImage(url);