Hi,
I'm having trouble finding the right code to write a short method to create a greyscale SImage from an array of ints representing text in binary form. For example, given the array [0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 1], an integer width 4, and an integer height 4, I want to be able to return an SImage with pixel values:
0 0 0 0
128 0 128 0
0 0 0 128
0 128 0 128
The code also needs to handle if the array is too short to fill every pixel values after with zeros and to stop if the image pixels run out first.
I'm assuming some kind of loops will be needed, but am unsure of what code to use.

private SImage convert2Image(int[] bits, int width, int height) {
       BufferedImage image = new BufferedImage(width, height,  
                                        BufferedImage.TYPE_BYTE_GRAY);   

....................
   }

Any suggestions?

See this thread. After creating the image use the getRGB method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.