Qt编程之转换成8,16bit的灰度图

代码大致是下面这样的。是8bit的灰度图,不是16bit。

 QString img_path = "C:\\Users\\Yajun Dou\\Desktop\\test.bmp";
QImage buff(img_path);
QImage image;
uchar* pImageData1 = NULL,*pImageData2 = NULL; pImageData1 = buff.bits(); image = buff.convertToFormat(QImage::Format_Indexed8); QVector<QRgb> table();
for( int i = ; i < ; ++i )
{
table[i] = qRgb(i,i,i);
} image.setColorTable(table); for(int i =; i< image.width();i++)
{
for(int j=; j< image.height();j++)
{
QRgb pix_value = image.pixel(i,j);
image.setPixel(i,j,qGray(pix_value));
} } pImageData2 = image.bits();
image.save("D:\\out.bmp",,);

references:

http://qt-project.org/faq/answer/how_can_i_convert_a_colored_qpixmap_into_a_grayscaled_qpixmap

http://www.qtcentre.org/threads/46596-How-to-convert-a-32-bit-RGB-image-to-8-bit-gray-scale-image

http://www.qtcentre.org/threads/19296-is-there-a-simple-and-quick-way-to-convert-color-images-to-gray-image

http://www.qtcentre.org/threads/15186-QImage-Greyscale-8-bits-pixel

http://*.com/questions/15672743/convert-16-bit-grayscale-to-qimage

上一篇:asp.net core webapi 服务端配置跨域


下一篇:Salesforce小知识:在简档中设置Visualforce页面的权限