Java BufferedImage Create getBufferedImage(Component comp, BufferedImage image)

Here you can find the source of getBufferedImage(Component comp, BufferedImage image)

Description

Mendapatkan BufferedImage dari sebuah komponen

License

Open Source License

Parameter

Parameter Description
comp komponen sumber
image gambar target

Declaration

public static void getBufferedImage(Component comp, BufferedImage image) 

Method Source Code

//package com.java2s;
/*//  w  w  w .  java  2  s. co  m
 *  Copyright (c) 2011, StripBandunk and/or its affiliates. All rights reserved.
 * 
 *       http://stripbandunk.com/
 * 
 *  STRIPBANDUNK PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

import java.awt.Component;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {
    /**
     * Mendapatkan BufferedImage dari sebuah komponen
     * @param comp komponen sumber
     * @param image gambar target
     */
    public static void getBufferedImage(Component comp, BufferedImage image) {
        // Mendapatkan Graphics2D dari image
        Graphics2D g2 = image.createGraphics();

        // menggambar seluruh komponen 
        comp.paint(g2);

        // menghilangkan Graphics2D
        g2.dispose();
    }

    /**
     * Mendapatkan gambar dari sebuah komponen
     * @param comp komponen sumber
     * @return gambar BufferedImage
     */
    public static BufferedImage getBufferedImage(Component comp) {
        // Membuat gambar BufferedImage
        BufferedImage image = new BufferedImage(comp.getWidth(), comp.getHeight(), BufferedImage.TYPE_INT_ARGB);

        // menggambar dengan memanggil metode getBufferedImageFromComponent();
        getBufferedImage(comp, image);

        // menggembalikan gambar
        return image;
    }
}

Related

  1. convertToBufferedImage(BufferedImage image, int imageType)
  2. getBufferedImage(byte[] imgStr)
  3. getBufferedImage(File file)
  4. getBufferedImage(String imageFile, Component c)
  5. getBufferedImage(String imagePath)
  6. getBufferedImageAsType(int type, BufferedImage image, int sizeX, int sizeY)