zoukankan      html  css  js  c++  java
  • Qt编程之转换成8,16bit的灰度图

    代码大致是下面这样的。是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

  • 相关阅读:
    011-通过网络协议解析网络请求-DNS-ARP-TCPIP
    010-HTTP协议
    009-DNS域名解析系统
    008-ICMP协议(网络控制文协议)
    007-IP报文协议
    007-排序算法-堆排序
    006-排序算法-希尔排序
    007-Linux 查看端口
    005-排序算法-归并排序
    004-排序算法-选择排序
  • 原文地址:https://www.cnblogs.com/foohack/p/3889813.html
Copyright © 2011-2022 走看看