为8位灰度阵列转换成RGB:
int[] greyArraySource = ...;
int[] rgbArray = new int[greyArraySource.length];
for(int i=0; i<greyArraySource.length; i++) {
int color = (int)aImageData[i];
if(color < 0)
{
color = 256 + color;
}
rgbArray[i] = Color.rgb(color,color,color);
}
后,您可以将您的RGB数组转换为BufferedImage:
// Initialize BufferedImage
int width = ...;
int height = ...;
BufferedImage bufferedImage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
// Set RGB array to the BufferedImage
BufferedImage.setRGB(0,0,BufferedImage.getWidth(),
BufferedImage.getHeight(),rgbArray, 0, BufferedImage.getWidth());
转换BuffuredImage以JPG:
File outputfile = new File("image.jpg");
ImageIO.write(bufferedImage, "jpg", outputfile);
看来你的图像是4位的,所以你需要改变转换。如果你发布数组值,也许我可以检查。
@Geekar您已经成功地得到你的形象吗? – LaurentY