爲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