如何在Java中将16位灰度图像转换为RGB图像? [英] How to convert 16 bit Gray Scale image to RGB image in java?
问题描述
我正在使用Netbeans平台在Java Swing中制作一个桌面应用程序.我想将16位灰度图像转换为RGB图像.我该怎么办?
I'm making a desktop app in Java Swing using the Netbeans platform. I want to convert a 16 bit gray scale image to an RGB image. How can I do that?
推荐答案
Incompl描述的getRGB/setRGB方法应该起作用.但是,如果我没记错的话,它的性能相当差(这些方法做了很多工作,在这种情况下是不必要的).我认为,使用新图像并让Java优化从BufferedImage.TYPE_USHORT_GRAY
到BufferedImage.TYPE_INT_RGB
的转换会更快得多:
The getRGB/setRGB method described by Incompl should work. But, its performance is rather poor, if I remember correctly (these methods do a lot of work that is unnecessary in this case). I think it would be much faster to draw on the new image and let Java to optimize the conversion from BufferedImage.TYPE_USHORT_GRAY
to BufferedImage.TYPE_INT_RGB
:
int width = grayImage.getWidth();
int height = grayImage.getHeight()
BufferedImage newImage = new BufferedImage(
width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = newImage.getGraphics();
g.drawImage(grayImage, 0, 0, null);
g.dispose();
这篇关于如何在Java中将16位灰度图像转换为RGB图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!