This is now solved. See the code. It works now!!!
The Initial question was:
I need to store an image , received in a byte[] array, into a fits file. I'm using java 8 and fits.jar lib (nom.tam.fits).
The following code seems to work in first instance but when I open the fits file in ds9, it displays a narrow band instead of the image. In the following code, data is the byte[] array for the image (one byte per pixel)
Fits f = new Fits();
int[] uBytes = new int[imageData.length];//the byte[] with the pixels
for (int i = 0; i < data.length; i+=1) {
uBytes[i] = (int) (imageData[i] & 0xff);
}
int dims[] = new int[]{imageSize_x, imageSize_y};
int [][] data = (int[][]) ArrayFuncs.curl(uBytes,dims);
BasicHDU h= Fits.makeHDU(data);
f.addHDU(h);
OutputStream os = new FileOutputStream("testImage.fits");
BufferedDataOutputStream s= new
BufferedDataOutputStream(os);
f.write(s);
f.close();
I must confess I was a bit silly since I've already managed to solve the same problem when tried to display the image with JavaFX JavaFX. Displaying an image from byte[]