现在解决了! 解决方案在下面的代码中
我需要将Image
从以字节数组形式接收的像素(每个像素一个字节)显示为ImageView
。
图像最初是png格式。
private WritableImage convertByteArrayToImage(byte[] pixels, int width,int height) {
int imageType= Integer.valueOf(expTime.getText());
int[] ints = new int[pixels.length];
for (int i = 0; i < pixels.length; i++) {
ints[i] = (int) pixels[i] & 0xff;
}
BufferedImage bImg
= new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
WritableRaster raster = (WritableRaster) bImg.getData();
raster.setPixels(0, 0, width, height, ints);
bImg.setData(raster);
return SwingFXUtils.toFXImage(bImg, null);
}
谢谢