Here you can find the source of bufferedImageFromImage(final Image image)
Parameter | Description |
---|---|
image | An Image to be converted to a BufferedImage. |
public static BufferedImage bufferedImageFromImage(final Image image)
//package com.java2s; import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.BufferedImage; public class Main { /**/* w ww . j a va 2 s .c om*/ * Creates a {@link BufferedImage} from an {@link Image}. * * @param image An Image to be converted to a BufferedImage. * @return A BufferedImage instance of the same given image. */ public static BufferedImage bufferedImageFromImage(final Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; } final BufferedImage out = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); final Graphics2D g2d = out.createGraphics(); g2d.drawImage(image, 0, 0, null); g2d.dispose(); return out; } }