0

Im having a double pointer char of dataBuffer[1000][1000] in that char pointer some places i will make hex value 0xFF and remaining 0x00 (for openGL plotting)

now i want it to show it as a QWidget with the hex value in pixel.

i found QImage we can map 1000x1000 pixels but i dont know how to map hex value of char to pixels .

please help me , thanks in advance.

Wagmare
  • 1,354
  • 1
  • 24
  • 58

1 Answers1

0

You may try to do the following:

First, construct QImage from your buffer using this constructor: QImage(const uchar* data, int width, int height, Format format), using QImage::Format_Indexed8 as format i.e.

QImage img(dataBuffer, 1000, 1000, QImage::Format_Indexed8)

Second, Initialize color translation map: it should be QVector<QRgb>, so you need to do something like this:

QVector<QRgb> colorMap(256);
colorMap[255] = QRgb(255, 255, 255); // Any color of your choice
// probably some other mappings

Then use QImage::convertToFormat like this:

QImage converted = img.convertToFormat(QImage::Format_RGB32, colorMap)

This will convert it to RGB. Basically, that's it, now you can draw this image on your widget or save it to file.

user2155932
  • 760
  • 3
  • 9
  • First tnx for ur best reply .. but im facing some problem in implementing ur logic . QVector colorMap(256); colorMap[255] = QRgb(255, 255, 255); throws me an error : Expression list treated as compound expression in functional cast[-F premissive].. can u please help me in sort this out .. thx once again :) – Wagmare Mar 19 '13 at 09:36
  • I Fixed it sir... for(int row =0; row < 2048; row ++) for(int column =0; column < 2048; column ++) { m_dataArray[row][column] = 0x00; } QImage img(*m_dataArray, 2048, 2048, QImage::Format_Indexed8); QVector colortable(256); colortable[255] = qRgb(255,255,255); QImage converted = img.convertToFormat(QImage::Format_RGB32, colortable); m_graphicsScene->addPixmap(QPixmap::fromImage(converted)); – Wagmare Mar 19 '13 at 10:08
  • Thx user2155932 for reply. this is what i did a double ponter unsigned char array unsigned char **m_dataArray; and i plotted it as http://pastebin.com/vVRetzPA but the image looks little odd as it has white spots on a black image. Please help me to resolve it. . – Wagmare Mar 19 '13 at 10:26