• 9603阅读
  • 11回复

qt中图像处理问题!!! [复制链接]

上一主题 下一主题
离线jxq19881013
 

只看楼主 倒序阅读 楼主  发表于: 2009-05-22
我从一个设备中,读取到了图像的数据,是一些十六进制数字,如何根据这些图像数据来生成一个图像文件,请高手帮忙!!!
这是我自己写的代码,没有实现上述功能;
/***************************************************************************************/
void FileOperation::save_image(QString image_name,char *image_content)
  {
     QImage fingprinter_image=QImage(image_content);//image_content 接受到的是一个数组中的数据
     fingprinter_image.save("./fingprinter_image/"+image_name,"PNG");
  }
/*************************************************************************************/



这是我最新的代码,能够生成图片,但是显示出来的东西不是我想要的,高手看看有什么问题吗?
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void FileOperation::save_image(QString image_name,uchar *image_content)
  {
     QBitmap bitmap=QBitmap(280,280,image_content,TRUE);
     QImage fingprinter_image=bitmap.convertToImage();
     fingprinter_image.save("./fingprinter_image/"+image_name,"BMP");
    // printf("image_name is %s",image_name);
  }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

下面是我参考的资料,我用的是2.3.7和2.3.2的版本
///////////////////////////////////////////////////////////////
The QBitmap class provides monochrome (1-bit depth) pixmaps. More...

#include <qbitmap.h>

Inherits QPixmap.
//////////////////////////////////////////////////////
QBitmap::QBitmap ( int w, int h, const uchar * bits, bool isXbitmap = FALSE )
Constructs a bitmap with width w and height h and sets the contents to bits.
The isXbitmap flag should be TRUE if bits was generated by the X11 bitmap program. The X bitmap bit order is little endian. The QImage documentation discusses bit order of monochrome images.

Example (creates an arrow bitmap):

        uchar arrow_bits[] = { 0x3f, 0x1f, 0x0f, 0x1f, 0x3b, 0x71, 0xe0, 0xc0 };
        QBitmap bm( 8, 8, arrow_bits, TRUE );

///////////////////////////////////////////////////////////////////////////////////////////////////qpixmap类中的方法/////////////////////////
QImage QPixmap::convertToImage () const
Converts the pixmap to a QImage. Returns a null image if it fails.
If the pixmap has 1-bit depth, the returned image will also be 1 bit deep. If the pixmap has 2- to 8-bit depth, the returned image has 8-bit depth. If the pixmap has greater than 8-bit depth, the returned image has 32-bit depth.

Note that for the moment, alpha masks on monochrome images are ignored.


See also convertFromImage().
///////////////////////////////////////////////qimage类中的方法///////////////////////////////////////////////////////////////////////
bool QImage::save ( const QString & fileName, const char * format, int quality = -1 ) const
Saves the image to the file fileName, using the image file format format and a quality factor of quality. quality must be in the range 0..100 or -1. Specify 0 to obtain small compressed files, 100 for large uncompressed files, and -1 (the default) to use the default settings.
Returns TRUE if the image was successfully saved; otherwise returns FALSE.


See also load(), loadFromData(), imageFormat(), QPixmap::save() and QImageIO.
[ 此帖被jxq19881013在2009-05-28 10:20重新编辑 ]
离线cyndy
只看该作者 1楼 发表于: 2009-05-25
请教LZ, 在QT/E中,如何对一个设备进行控制呀?比如一个led灯的设备文件/dev/led 。谢谢
离线jackyzhang
只看该作者 2楼 发表于: 2009-05-27
只有图像的数据,没有信息数据,需要使用另外一个构造函数
离线jxq19881013

只看该作者 3楼 发表于: 2009-05-27
把设备作为一个文件操作就可以了!!!
离线cyndy
只看该作者 4楼 发表于: 2009-05-27
在QT-E中 怎么进行操作啊?
离线jxq19881013

只看该作者 5楼 发表于: 2009-05-27
这是我最新的代码,能够生成图片,但是显示出来的东西不是我想要的,高手看看有什么问题吗?
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void FileOperation::save_image(QString image_name,uchar *image_content)
  {
     QBitmap bitmap=QBitmap(280,280,image_content,TRUE);
     QImage fingprinter_image=bitmap.convertToImage();
     fingprinter_image.save("./fingprinter_image/"+image_name,"BMP");
    // printf("image_name is %s",image_name);
  }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
离线jackyzhang
只看该作者 6楼 发表于: 2009-05-27
图像格式没有指定,是8位,16位,32位?
离线jackyzhang
只看该作者 7楼 发表于: 2009-05-27
    QImage(uchar *data, int width, int height, Format format);
    QImage(const uchar *data, int width, int height, Format format);
    QImage(uchar *data, int width, int height, int bytesPerLine, Format format);
    QImage(const uchar *data, int width, int height, int bytesPerLine, Format format);
这几个函数试下,注意format的值
离线jxq19881013

只看该作者 8楼 发表于: 2009-05-28
图像是采用8位的灰度值!!!
离线jxq19881013

只看该作者 9楼 发表于: 2009-05-29
已经解决!!!
离线cpq37
只看该作者 10楼 发表于: 2009-06-05
mark
离线cszhoujin
只看该作者 11楼 发表于: 2009-10-20
楼主,你是用什么方法解决的啊?我也遇到了这个问题,一直没有解决!希望你能给点建议啊!
快速回复
限100 字节
 
上一个 下一个