[Qt-interest] grayscale image looks faded

Mihail Naydenov mlists at ymail.com
Thu Apr 29 08:37:31 CEST 2010


It will look "faded" if you simply cast-convert one to another, because the input data and the output data (char) have diff max-values.
This is - if "white" or max value in your data is for instance 128, this "mapped" to char will be "half-white" char or gray color.

How to convert one bit depth to another is OT in this list, I recommend using some image library (FreeImage is a personal favorite) 
The image lib will do the work for you (incl. other conv. like 16 bit to 8), and its forum is the place to ask image related questions.

thumbs up
MihailNaydenov


>
>From: caius ligarius <caius9090 at gmail.com>
>To: qt-interest at trolltech.com
>Sent: Thu, April 29, 2010 2:50:31 AM
>Subject: [Qt-interest] grayscale image looks faded
>
>>Hi,
>
>I am new to Qt and am trying to display an 8Bit grayscale image using QGraphicsScene/QGraphicsView. I finally got some image to be displayed in the viewport but the image looks faded (or it's dynamic range seems low). Below is the code I use. 
>
>1) My original image is in 1D 'int' array (rbf.heData) so I first convert to uchar array (pDataB)
>2) After this I create a QImage and pass it as a pixmap to QGraphicsScene
>3) QGraphicsView is then used to set the above QGraphicsScene 
>
>******************************
>    BYTE* pDataB = new BYTE[rbf.heData->rows*rbf.heData->cols];
>    for(i = 0;i < rbf.heData->rows*rbf.heData->cols; i++)
>    {
>        BYTE tempchar[1]={0};
>>        _itoa(rbf.heData->pData[i],(char*)tempchar,10);
>        pDataB[i] = tempchar[0];
>    }
>    
>    QImage qi(pDataB, rbf.heData->cols, rbf.heData->rows, QImage::Format_Indexed8);
>    QGraphicsScene* scene = new QGraphicsScene;
>>    scene->setItemIndexMethod(QGraphicsScene::NoIndex);
>    scene->addPixmap(QPixmap::fromImage(qi));
>    ui.graphicsView->setScene(scene);
>
>    ui.graphicsView->show();
>
>***********************************
>
>
>1) Why does the image appear faded?
>2) I also need to display a 16BIt Image, how will the above code change for this?
>
>
>Thanks,
>Caius
>
>


      



More information about the Qt-interest-old mailing list