Qt 图像类 QImage QPixmap QBitmap QPicture 之区别与用途

42 篇文章 1 订阅

 自己整理的,备忘录,参考Qt自带帮助:

qthelp://com.trolltech.qt.486/qdoc/qpixmap.html#details


Qt provides four classes for handlingimage data:QImage, Pixmap, QBitmapandQPicture.

继承关系:

QPaintDevice->QPixmap->QBitmap

 QPaintDevice->QImage

 QPaintDevice->QPicture

 

QPixmap:   is an off-screen image representation thatcan be used as a paint device

QBitmap:   provides monochrome (1-bit depth) pixmaps

QImage :   provides a hardware-independent imagerepresentation that allows direct access to the pixel data, and can be used asa paint device

QPicture:is a paint device that records and replays QPainter commands. 

 

QImage is designed and optimizedfor I/O, and for direct pixel access and manipulation,

QPixmap is designed and optimizedfor showing images on screen.

QBitmap is only a convenienceclass that inherits QPixmap, ensuring a depth of 1. The isQBitmap() functionreturns true if a QPixmap object is really a bitmap, otherwise returns false.

QPicture class is a paint devicethat records and replays QPainter commands.

 ------------------------------------QPixmap 说明-------------------------------------------------------

A QPixmapcan easily be displayed onthe screen using QLabel or one of QAbstractButton's subclasses (suchasQPushButton and QToolButton). QLabel has a pixmap property, whereasQAbstractButton has an icon property.

In addition to the ordinaryconstructors, a QPixmap can be constructed using the static grabWidget() andgrabWindow() functions which creates a QPixmap and paints the given widget, orwindow, into it.

QPixmap objects can be passed aroundby value since the QPixmap class uses implicit data sharing. For moreinformation, see the Implicit Data Sharing documentation. QPixmap objects canalso be streamed.

Note that the pixel data in a pixmapis internal and is managed by the underlying window system. Because QPixmap isaQPaintDevice subclass, QPainter can be used to draw directly onto pixmaps.Pixels can only be accessed through QPainterfunctions or by converting theQPixmap to a QImage. However, the fill() function is available for initializingthe entire pixmap with a given color.

There are functions to convert betweenQImage and QPixmap. Typically, the QImage class is used to load an image file,optionally manipulating the image data, before the QImage object is convertedinto a QPixmap to be shown on screen. Alternatively, if no manipulation isdesired, the image file can be loaded directly into a QPixmap. On Windows, theQPixmap class also supports conversion between HBITMAP and QPixmap. On Symbian,the QPixmap class also supports conversion between CFbsBitmap and QPixmap.

 ---------------------------------QPicture说明--------------------------------------------------------------------------------

 

//QPicture例子:
         QPicture picture;
        QPainter painter;
         painter.begin(&picture);           // paint in picture
         painter.drawEllipse(10,20, 80,70); //draw an ellipse
         painter.end();                     // painting done
        picture.save("drawing.pic");       //save picture
 
         QPicture picture;
        picture.load("drawing.pic");           // load picture
         QPainter painter;
         painter.begin(&myImage);               // paint in myImage
         painter.drawPicture(0, 0,picture);    // draw the picture at (0,0)
         painter.end();                         // painting done


---------------------------------QImage说明-------------------------------------------------------------------------------------------


QImage读写  图像文件:

QImage provides several ways of loading an image file: 

The file can be loaded when constructing the QImage object, or by using theload()orloadFromData()functions later on. QImage also provides the staticfromData()function, constructing a QImage from the given data. When loading an image, the file name can either refer to an actual file on disk or to one of the application's embedded resources. See The Qt Resource System overview for details on how to embed images and other resource files in the application's executable.
Simply call the save() function to save a QImage object.


 QImage image(3, 3, QImage::Format_RGB32);
 QRgb value;

 value = qRgb(189, 149, 39); // 0xffbd9527
 image.setPixel(1, 1, value);

 value = qRgb(122, 163, 39); // 0xff7aa327
 image.setPixel(0, 1, value);
 image.setPixel(1, 0, value);

 value = qRgb(237, 187, 51); // 0xffedba31
 image.setPixel(2, 1, value);



 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值