将 BufferedImage 转换为另一种类型 [英] Converting a BufferedImage to another type
本文介绍了将 BufferedImage 转换为另一种类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从源(File
s、InputStream
s、URL
s)读取图像最方便的方法是:
The most convenient method to read an image from a source (File
s, InputStream
s, URL
s) is:
BufferedImage myImage = ImageIO.read( source );
但是,如何将 myImage
转换为 BufferedImage.TYPE_USHORT_565_RGB
格式?
But then, how to convert myImage
to a BufferedImage.TYPE_USHORT_565_RGB
format?
推荐答案
你可以新建一个所需类型的BufferedImage,然后在上面绘制原图,比如:
You can create a new BufferedImage of the required type and then draw the original image on it, something like:
BufferedImage bufImg = ImageIO.read( imageURL );
BufferedImage convertedImg = new BufferedImage(bufImg.getWidth(), bufImg.getHeight(), BufferedImage.TYPE_USHORT_565_RGB);
convertedImg.getGraphics().drawImage(bufImg, 0, 0, null);
这篇关于将 BufferedImage 转换为另一种类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文