Java Image Create getImage(JComponent component)

Here you can find the source of getImage(JComponent component)

Description

draw the component as an image

License

Apache License

Parameter

Parameter Description
component a parameter

Declaration

public static BufferedImage getImage(JComponent component) 

Method Source Code


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

import javax.swing.*;

import java.awt.*;

import java.awt.image.*;

public class Main {
    /**// w ww  . j  a v  a  2 s  .c  om
     * draw the component as an image
     *
     * @param component
     * @return
     */
    public static BufferedImage getImage(JComponent component) {
        BufferedImage ret = new BufferedImage(component.getWidth(), component.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        Graphics g = ret.getGraphics();
        component.paint(g);
        g.dispose();
        return ret;
    }
}

Related

  1. getImage(Component component)
  2. getImage(File imageFile)
  3. getImage(final int width, final int height)
  4. getImage(final String name)
  5. getImage(ImageIcon imageIcon)
  6. getImage(Object obj, String filePath)
  7. makeImage(double[][] levels)
  8. makeImageResizer(String srcImgPath, String targerPath, int scaledWidth, int scaledHeight, boolean preserveAlpha)