Qt 常用类 (7)—— QPixmap
来源:互联网 发布:淘宝模板在线制作 编辑:程序博客网 时间:2024/06/06 00:54
QPixmap 类代表图像,实现在 QtGui 共享库中。
构造
以下构造函数生成的 QPixmap 对象为空图像:
QPixmap(); // 构造一个大小为 0 的空图像
以下构造函数生成大小的 QPixmap 对象,但图像数据未初始化:
QPixmap(const QSize &size); // 构造大小为 size 的图像,图像数据未初始化QPixmap(int width, int height); // 等价于 QPixmap(QSize(width, height));
以下构造函数能够从指定的文件中加载图像并生成 QPixmap 对象:
QPixmap(const QString &filename, const char *format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
其各个参数的含义解释如下。
1) filename: 文件名。
2) format: 字符串,表示图像文件的格式,如果为 0,将进行自动识别。
3) flags:表示颜色的转换模式。
如果图像文件加载失败则产生空图像,这里 flags 参数有以下取值。
1) Qt::AutoColor:由系统自动决定。
2) Qt::ColorOnly:彩色模式。
3) Qt::MonoOnly:单色模式。
图像参数
以下成员函数可以获得 QPixmap 对象所表示的图像的相关信息:
int depth() const; // 颜色深度,既每像素所占的比特数int width() const; // 图像宽度,单位是像素int height() const; // 图像高度,单位是像素QSize size() cosnt; // 图像的大小,即 QSize(width(), height());QRect rect() const; // 图像的矩形区域,即 QRect(QPoint(0,0),size());
加载和保存图像
用下面的成员函数可以从文件加载图像:
bool load(const QString &filename, const char *fornat = 0, Qt::ImageCoversionFlags flags = Qt::AutoColor);
bool save(const QString &filename, const char *format = 0, int quality = -1) const;
其各个参数及返回值的含义解释如下。
1) filename:文件名。
2) format:字符串,表示图像文件的格式,如果为 0,将根据文件名的后缀自动确定文件格式。
3) quality:对于有损压缩的文件格式来说,它表示图像保存的质量,质量越低压缩率越大。取值范围为 0~100,-1 表示采用默认值。
4) 返回值:true 表示保存成功,false 表示保存失败。
判断
以下成员函数可以判断 QPixmap 对象是否为空图像:
bool isNull() const; // 判断是否为空图像
- Qt 常用类 (7)—— QPixmap
- Qt 常用类 (7)—— QPixmap
- Qt 常用类 (7)—— QPixmap
- Qt 常用类 —— QPixmap
- Qt常用类QPixmap
- Qt 常用类 (7)QPixmap/8--QIcon
- Qt绘 —— QPixmap 的使用
- Qt绘图——QPixmap的使用
- Qt QPainter QpinterPath QPixmap常用语句
- Qt图片绘图类QPixmap/QImage/QPicture
- Qt中图像类QImage,QPixmap
- QT QPixmap、QBitmap、QImage
- QPixmap类
- Qt的4个图像类QImage/QPixmap/QBitmap/QPicture
- Qt的4个图像类QImage/QPixmap/QBitmap/QPicture
- Qt的4个图像类QImage/QPixmap/QBitmap/QPicture .
- Qt的4个图像类QImage/QPixmap/QBitmap/QPicture
- Qt的4个图像类QImage/QPixmap/QBitmap/QPicture .
- 解决ilasm.exe无法编译 IL代码一例
- Source Insight中代码块注释(利用/**/)及取消注释实现方法
- 如何:对 Windows 窗体控件进行线程安全调用
- flex_音乐播放列表示例;
- 动画设计的12条基本原理
- Qt 常用类 (7)—— QPixmap
- ArcGIS中使用OracleSpatial在ArcGIS与使用ST_Geometry的不同
- linux-2.6.32内核中部分结构体
- SAP BW库存管理
- String各类运算符重载的编写示例
- JS 字符串便常量笔记
- Android NDK之一:什么是NDK?
- 不使用库函数将字符串转化为数字 实现
- 由链表实现的容器