Hi,

I am trying to read data from a file, convert it to an image and display it. The trouble starts with the file: it is made of a txt format header (often 4092 bytes) and the rest is unsigned int (0 to 65535, 2 bytes). The unsigned int represent the data that I wish to display as an image (grayscale).
I am a newbie and the code may not make much more sense after few days of trials and mostly errors.

So my goal is to read the file, skip the text part (I can get the size of the text header), read the data into some array, convert the array to an image, display the image. All of that the fastest possible.

Here is my not working code:
Qt Code:
  1. m_scene->clear();
  2. QVector<quint16> MyArray;
  3.  
  4. QFile file(temp); //temp is QString with the path and file name
  5.  
  6. if (file.open(QIODevice::ReadOnly))
  7. {
  8. file.seek(dlgHeaderBytes);
  9. QDataStream in(&file);
  10.  
  11. quint16 item;
  12. for (int i=0;i<((file.size()-HeaderBytes)/2);i++)
  13. {
  14. in >> item;
  15. MyArray <<item;
  16. }
  17. m_scene->addText("The file "+temp+" was opened succesfully.\n");
  18. QImage MyImage( dlgNX, dlgNY, QImage::Format_Indexed8 );
  19. QVector<QRgb> colorTable;
  20. for (int i = 0; i < 256; i++) colorTable.push_back(QColor(i, i, i).rgb());
  21. MyImage.setColorTable(colorTable);
  22.  
  23. for (int i=0;i<NX;i++)
  24. {
  25. for (int j=0;j<NY;j++)
  26. {
  27. MyImage.setPixel(i, j, uint(MyArray[i+j]/256)); //this to be changed but only when previous steps are working
  28. }
  29. }
  30.  
  31. m_scene->setBackgroundBrush(MyImage);
  32.  
  33. }
To copy to clipboard, switch view to plain text mode 

I don't think that I am reading the data properly from the file. I am not sure on how to handle qdatastream. I have tried while qdatastream.atend() but nothing seems to be read...

Any help very appreciated.