Hi, thanks for the reply , but that does not work
. I tried to convert to QImage::Format_Indexed8, but the grayscale image is not proper.
Added after 1 30 minutes:
it Worked when I did like this
QImage ImageActionConvert
::convertToGray(*pInputImage
) {
if ( pInputImage && !pInputImage->isNull() )
{
QImage retImg
(pInputImage
->width
(),pInputImage
->height
(),
QImage::Format_Indexed8);
QVector<QRgb> table( 256 );
for( int i = 0; i < 256; ++i )
{
table[i] = qRgb(i,i,i);
}
retImg.setColorTable(table);
for(int i =0; i< pInputImage->width();i++)
{
for(int j=0; j< pInputImage->height();j++)
{
QRgb value = pInputImage->pixel(i,j);
retImg.setPixel(i,j,qGray(value));
}
}
return retImg;
}
QImage ImageActionConvert::convertToGray(*pInputImage)
{
if ( pInputImage && !pInputImage->isNull() )
{
QImage retImg(pInputImage->width(),pInputImage->height(),QImage::Format_Indexed8);
QVector<QRgb> table( 256 );
for( int i = 0; i < 256; ++i )
{
table[i] = qRgb(i,i,i);
}
retImg.setColorTable(table);
for(int i =0; i< pInputImage->width();i++)
{
for(int j=0; j< pInputImage->height();j++)
{
QRgb value = pInputImage->pixel(i,j);
retImg.setPixel(i,j,qGray(value));
}
}
return retImg;
}
To copy to clipboard, switch view to plain text mode
Bookmarks