代码大致是下面这样的。是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://stackoverflow.com/questions/15672743/convert-16-bit-grayscale-to-qimage

Qt编程之转换成8,16bit的灰度图的更多相关文章

  1. 测底稳定NIOS开发之一:将nios产生的编程文件转换成jic (连载)

    将nios产生的编程文件转换成jic 前言: 基于某种原因,自从开始fpga开发和nios项目开发中,均为正常使用EDS IDE自带的flash programmer 进行成功的下载固化epcs程序. ...

  2. QT把widget转换成图片后打印

    from PyQt5.QtWidgets import (QApplication, QWidget, QTableWidget,QPushButton, QVBoxLayout, QTableWid ...

  3. Qt中int转换成QString

    (1) QString QString::number ( long n, int base = 10 ) [static] examle: long a = 48; QString s = QStr ...

  4. python的N个小功能(图片预处理:打开图片,滤波器,增强,灰度图转换,去噪,二值化,切割,保存)

    ############################################################################################# ###### ...

  5. 在windows下的QT编程中的_TCHAR与QString之间的转换

    由于在windows下的QT编程中,如果涉及到使用微软的API,那么不可避免使用_TCHAR这些类型,因此在网上查了一下,其中一个老外的论坛有人给出了这个转换,因此在这里做一下笔记 : )#ifdef ...

  6. 编程实现将一个N进制数转换成M进制数

    问题:编程实现将一个N进制数转换成M进制数.(c/c++.Java.Javascript.C#.Python) 1.Python 手写算法版 def conversion_num(num, src, ...

  7. 将任意音频格式文件转换成16K采样率16bit的wav文件

    此转换需要使用ffmpeg 假设有目录 d:\录音 目录有 张三.m4a, 李四.m4a xxx.m4a(其他任意格式音频触类旁通可以把 *.m4a改成*.*).批量转换成采样率16K,有符号,16b ...

  8. 零基础学QT编程

    吴迪.2010.1 北京航空航天大学出版社   Qt资源 CSDN QT http://bbs.csdn.net/forums/Qt/ QT编程网 http://www.qtbcw.com/ 编程论坛 ...

  9. Qt编程简介与基本知识

    1. 什么是Qt? Qt是一个基于C++的跨平台应用程序和UI开发框架.它包含一个类库,和用于跨平台开发及国际化的工具. 由挪威Trolltech公司开发,后被Nokia收购,目前被Digia公司收购 ...

随机推荐

  1. Visual Studio中的lib的链接顺序

    描述:如果有一个exe工程,它依赖于A.lib,B.lib,A.lib和B.DLL我同样有他们的源码工程.依赖顺序是这样的exe->A.lib->B.DLL.那么如果我改动了B的源码,编译 ...

  2. python sqlite3使用

    python sqlite3文档地址:http://docs.python.org/2/library/sqlite3.html The sqlite3 module was written by G ...

  3. logstash ArgumentError: comparison of String with 5 failed

    <pre name="code" class="html"><pre name="code" class="ht ...

  4. 黑马程序员_Java面向对象3_多态

    5.面向对象_多态 多态定义:某一种事物存在的多种形态. 例:动物中猫,狗. 猫这个对象对应的类型是猫类型. 猫 x = new 猫(); 同时猫也是动物的一种,也可以把猫称为动物. 动物 y = n ...

  5. Dynamic Binding & Static Binding

    Reference: JavaPoint BeginnerBook What is Binding Connecting a method call to the method body is kno ...

  6. 关于void*函数返回

    一. sample #include<iostream> using namespace std; void* test(void* pass) { return pass; } int ...

  7. 基本NT式驱动代码结构

    #include <ntddk.h> void DriverUnload(IN PDRIVER_OBJECT DriverObject);NTSTATUS MyCreateClose(IN ...

  8. Install and configure sql server 2008 express

    http://www.symantec.com/connect/articles/install-and-configure-sql-server-2008-express

  9. java常用方法

    public static int byte2int(byte b) { int i = b & 0x07f; if (b < 0) { i |= 0x80; } return i; } ...

  10. 使用面向 iOS 的本机插件扩展

    本文细致探讨了 Xcode(以 iOS 设备为目标)中的 PhoneGap(也称为 Apache Cordova)应用程序本机插件.如果您刚开始接触 PhoneGap 或者需要回顾 PhoneGap ...