Unsolved QImage conversion from 8 bit images to QImage::Format_Grayscale16
-
Hi,
I wanted to convert input 8 bit images to QImage::Format_Grayscale16.
Here is the below code snippet
QImage qimg("D:\image.png");
QImage qimg24;qimg24 = qimg.convertToFormat(QImage::Format_Grayscale16);
The input image is a 24 bit RGB888 png image.
I get segmebntation fault if i run this. Wont the converttoformat convert it to grayscale8 and upscale the input image to 16 bit?
Thanks
Sachin -
@SachinBhat said in QImage conversion from 8 bit images to QImage::Format_Grayscale16:
I get segmebntation fault if i run this
please provide the stack trace
-
@SachinBhat said in QImage conversion from 8 bit images to QImage::Format_Grayscale16:
QImage qimg("D:\image.png");
QImage qimg24;
qimg24 = qimg.convertToFormat(QImage::Format_Grayscale16);You have to check first if image loading was successful:
QImage qimg("D:\\image.png"); QImage qimg24; if(!img.isNull()) { qimg24 = qimg.convertToFormat(QImage::Format_Grayscale16); } else { qDebug() << "Failed to load image!"; }
-
I'd say your source image is nul because of :. Use double backslash ot forward slash.