Java JComponent to Image componentToImage(Component component, int resolution)

Here you can find the source of componentToImage(Component component, int resolution)

Description

component To Image

License

Open Source License

Declaration

public static BufferedImage componentToImage(Component component, int resolution) throws IOException 

Method Source Code


//package com.java2s;
//License from project: GNU General Public License 

import java.awt.Component;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import java.io.IOException;

public class Main {
    public static BufferedImage componentToImage(Component component, int resolution) throws IOException {
        BufferedImage img = new BufferedImage(component.getWidth() * resolution, component.getHeight() * resolution,
                BufferedImage.TYPE_INT_ARGB_PRE);
        Graphics2D g2 = (Graphics2D) img.getGraphics();
        g2.scale(resolution, resolution);
        g2.setColor(component.getForeground());
        g2.setFont(component.getFont());
        component.paintAll(g2);// w  w w. j  a  v  a  2s.c  o  m
        return img;
    }
}

Related

  1. buildImage(Component c)
  2. componentToImage(Component c)
  3. componentToImage(Component c)
  4. doScreenshotToFile(final Component container, final Path filePath, final String imageType)
  5. ensureImageLoaded(Component owner, Image image)
  6. findConnectedComponents(int[][] image)
  7. generateImageFileFromComponent(Component component, String filename, String Type)