Qt编程之转换成8,16bit的灰度图
2023-09-11 14:19:35 时间
代码大致是下面这样的。是8bit的灰度图,不是16bit。
1 QString img_path = "C:\\Users\\Yajun Dou\\Desktop\\test.bmp"; 2 QImage buff(img_path); 3 QImage image; 4 uchar* pImageData1 = NULL,*pImageData2 = NULL; 5 6 pImageData1 = buff.bits(); 7 8 image = buff.convertToFormat(QImage::Format_Indexed8); 9 10 QVector<QRgb> table(256); 11 for( int i = 0; i < 256; ++i ) 12 { 13 table[i] = qRgb(i,i,i); 14 } 15 16 image.setColorTable(table); 17 18 for(int i =0; i< image.width();i++) 19 { 20 for(int j=0; j< image.height();j++) 21 { 22 QRgb pix_value = image.pixel(i,j); 23 image.setPixel(i,j,qGray(pix_value)); 24 } 25 26 } 27 28 pImageData2 = image.bits(); 29 image.save("D:\\out.bmp",0,100); 30 31
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://stackoverflow.com/questions/15672743/convert-16-bit-grayscale-to-qimage
相关文章
- qt中xe运行缺少组件,Qt-c++桌面编程报错:qt.qpa.plugin: Could not find the Qt platform plugin “windows“ in ““,最终解决方案
- Qt-单例模式实例
- 【QT】测试Qt是否能连接上数据库
- QT工具——qt for vs
- Qt数据库应用9-数据导出组件使用方法
- Qt编写地图综合应用29-迁徙图
- Qt控件SDK使用示例大全
- Qt可视化大屏电子看板系统全平台效果图
- Qt开发经验小技巧131-140
- Qt音视频开发14-mpv读取和控制
- Qt编写地图综合应用12-路线查询
- Qt编写导航按钮
- Qt编写自定义控件插件路过的坑及注意事项
- Qt的编程风格与规范
- Install Qt 5 on Ubuntu(使用qt-opensource-linux-x64-5.7.0.run进行安装,而且是官方的wiki)
- Qt之QToolButton
- Qt之QSS(语法高亮)
- Qt Creator快捷键
- 报错 qt.qpa.plugin: Could not load the Qt platform plugin “xcb“ in ““ even though it was found
- Qt编程之通过鼠标滚轮事件缩放QGraphicsView里面的Item
- VS2010使用静态编译的qt库(Qt 5)
- Qt编程之QImage类小结
- Qt -------- 多线程编程
- Qt项目为程序添加软件图标