Image I / O API处理图像,因此您需要先从字节数组中制作图像,然后再将其写入。
byte[] aByteArray = {0xa,0x2,0xf,(byte)0xff,(byte)0xff,(byte)0xff};int width = 1;int height = 2;DataBuffer buffer = new DataBufferByte(aByteArray, aByteArray.length);//3 bytes per pixel: red, green, blueWritableRaster raster = Raster.createInterleavedRaster(buffer, width, height, 3 * width, 3, new int[] {0, 1, 2}, (Point)null);ColorModel cm = new ComponentColorModel(ColorModel.getRGBdefault().getColorSpace(), false, true, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); BufferedImage image = new BufferedImage(cm, raster, true, null);ImageIO.write(image, "png", new File("image.png"));假定字节数组每个像素有三个字节(红色,绿色然后是蓝色),并且值的范围是0-255。


![JAVA:如何从byte []创建.PNG图像? JAVA:如何从byte []创建.PNG图像?](http://www.mshxw.com/aiimages/31/454517.png)
