简体   繁体   中英

Suitable QImage format

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?

Qt's Mono format is 1-bit per pixel.

The only 8-bit format is QImage::Format_Indexed8 , so you'll need to create a color table with the 256 grays and pass it to QImage::setColorTable .

The table could be filled like this:

QVector<QRgb> colorTable;
for(int i=0; i<256; ++i)
   colorTable << qRgb(i,i,i);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM