Here you can find the source of imageToBufferedImage(Image img)
Parameter | Description |
---|---|
img | The Image to be converted |
public static BufferedImage imageToBufferedImage(Image img)
//package com.java2s; //License from project: Open Source License import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.BufferedImage; public class Main { /**/*from ww w.j ava2s . c o m*/ * Converts a given Image into a BufferedImage * * @param img * The Image to be converted * @return The converted BufferedImage */ public static BufferedImage imageToBufferedImage(Image img) { if (img instanceof BufferedImage) { return (BufferedImage) img; } // Create a buffered image with transparency BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); // Draw the image on to the buffered image Graphics2D bGr = bimage.createGraphics(); bGr.drawImage(img, 0, 0, null); bGr.dispose(); // Return the buffered image return bimage; } }