Java Image Load getImageFromSource(JPanel source, Dimension dim)

Here you can find the source of getImageFromSource(JPanel source, Dimension dim)

Description

get Image From Source

License

Open Source License

Declaration

static BufferedImage getImageFromSource(JPanel source, Dimension dim) 

Method Source Code


//package com.java2s;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;

public class Main {
    static BufferedImage getImageFromSource(JPanel source, Dimension dim) {
        int width = dim.width;
        int height = dim.height;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics g = image.createGraphics();
        Rectangle originalBounds = source.getBounds();
        source.setBounds(0, 0, width, height);
        source.updateUI();/*from   w w  w.ja  v a2 s.c  om*/
        source.paint(g);
        source.setBounds(originalBounds);
        g.dispose();
        return image;
    }
}

Related

  1. getImage(String text, boolean clockwise)
  2. getImage(String url)
  3. getImage(URL url)
  4. getImageFromClassResource(Class cls, String resource)
  5. getImageFromFile(String fileName)
  6. getLocal(String imagePath)
  7. loadImage(File original)
  8. loadImage(final String src)
  9. loadImage(InputStream s)