How to create Image From Array of Pixel Values and known width and height..?

岁酱吖の 提交于 2019-12-06 11:07:26
npinti

As stated in this previous SO post:

public static Image getImageFromArray(int[] pixels, int width, int height) {
            BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            WritableRaster raster = (WritableRaster) image.getData();
            raster.setPixels(0,0,width,height,pixels);
            return image;
        }

If you are having trouble understanding what the parameters are, you should take a look at the Java Documentation.

You could:

 InputStream is = new ByteArrayInputStream(rgb);
 Image img = ImageIO.read(is);

rgb should be a byte array.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!