Hi,

with Qt3 I have done this a lot, and now I need to convert and display 16bit gray scale.
But what ever I tried so far either gives me a uniform gray image (even if the buffer is empty) or no image at all.
I am a bit lost, maybe one of you can see what it is I am missing?
Efficiency is not an issue.
I just want to see the image.
The buffer is checked, and is valid, with a valid image (saved to file through grabbing lib). plus, I see in the debugger the contents.
I never get a black image even if the buffer is all full with '0'.
After setting the data in to the image, my QImage object returns false on isNull().
So I am quite sure my problem is format issue, not data issue.

Here is my code :
Qt Code:
  1. QImage convert16to8mono(unsigned short *inBuff, int sizeBytes, unsigned char *outBuff)
  2. {
  3. //convert 16 to 8 bit
  4. for(int i=0; i<sizeBytes/2; i++)
  5. outBuff[i] = (((double)inBuff[i]) / 0xFFFF) * 255;
  6.  
  7. QImage qimage(1280,960,QImage::Format_Indexed8);
  8. qimage.setNumColors(256);
  9. for(int i=0; i<256; i++)
  10. qimage.setColor(i,qRgb(i,i,i));
  11.  
  12. //trail 1
  13. //qimage.loadFromData(outBuff,sizeBytes/2,0/*BMP*/); //this is raw data, so there are no format specific headers etc.
  14. //trail 2
  15. memcpy(qimage.bits(),outBuff,sizeBytes/2);
  16.  
  17. //trail 3 :
  18. // for(int y=0,i=0;y<960; y++)
  19. // for(int x=0; x<1280; x++,i++)
  20. // qimage.setPixel(x,y,outBuff[i]);
  21.  
  22. return qimage;
  23. }
To copy to clipboard, switch view to plain text mode 

P.S
the contents of outBuff is also checked, and it has plausible values.