1

I'm having a one Channel image, and want to display it in a QImage

IplImage *img=cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 1);

Knowing that When converting from an IplImage* to QImage, I did what is follow:

uchar* img_d=(uchar*) img->imageData;
    QImage img_direction((uchar*)img_d, img->width, img->height, QImage::Format_Mono);

I'm not pretty sure about the Mono format that I have set, even the displayed QImage would be scrambled!

What would be the suitable QImage format for the case of a B&W image?

4

1 回答 1

2

Qt 的 Mono 格式是每像素 1 位。

唯一的 8 位格式是QImage::Format_Indexed8,因此您需要创建一个具有 256 个灰度的颜色表并将其传递给QImage::setColorTable

该表可以这样填充:

QVector<QRgb> colorTable;
for(int i=0; i<256; ++i)
   colorTable << qRgb(i,i,i);
于 2013-05-13T12:29:28.713 回答