0

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?

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by masijade
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.