How to convert a boolean array to a GIF image file (and vice versa)?
Posted on 2004-04-15
I have an application where I need to do the following:
I have a two-dimensional array containing boolean values. I would like to convert these data into an image such that 'true' array elements become 'white' pixels and 'false' array elements become 'black' pixels. Then I want to save the image to a file in GIF or PNG format.
Conversely, I want to import a GIF or PNG image into a boolean array, such that white pixels become true elements and non-white pixels become false elements.
My array of boolean values uses standard [row][column] ordering of the subscripts, i.e. myArray is the top left corner of the image and myArray[height-1][width-1] is the bottom right corner.
I'm using J2SE v1.4.2.