如何在Java中将16位灰度图像转换为RGB图像? [英] How to convert 16 bit Gray Scale image to RGB image in java?

查看:334
本文介绍了如何在Java中将16位灰度图像转换为RGB图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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_GRAYBufferedImage.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆