Java中如何将图像转换为BufferedImage呢?
下文笔者讲述使用java代码将图像转换为BufferedImage对象的方法分享,如下所示:
实现思路:
1.只需将图像转换为Image对象
2.将Image对象放入BufferedImage实例化对象中即可
例:
public static BufferedImage toBufferedImage(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;
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


