美文网首页
Qt之QImageWriter

Qt之QImageWriter

作者: YBshone | 来源:发表于2017-05-24 19:44 被阅读0次

前言:

话不多说,自己上码

QImageWriter类为写入图像至文件或设备提供了一个独立的接口。QImageWriter支持格式特定的选项(如:质量和压缩率),可以在存储图像之前进行设置。如果不需要这些选项,可以使用QImage::save()或QPixmap::s


帅
// 源图像
QImage image(":/Images/logo");

// 目标图像
QImageWriter writer("AuthorLogo.jpeg", "jpeg");
if (writer.supportsOption(QImageIOHandler::Description))
{
    // 设置描述信息
    writer.setText("Author", "Mr Wang");
    writer.setText("Description", "Qter");
}
writer.setQuality(100);
if (writer.canWrite())
{
    // 写入图片至文件AuthorLogo.jpeg
    writer.write(image);
}
else
{
    // 获取错误信息
    QImageWriter::ImageWriterError error = writer.error();
    QString strError = writer.errorString();
    qDebug() << "Last Error : " << strError;
}

这时,就会根据源图像(:/Image/logo资源文件)生成一张AuthorLogo.jpeg的图像,并且图像里面包含”Author”“以及”Description”对应的信息。

为什么图片上看不到呢?(⊙o⊙)…这时因为保存的信息在图片的数据中,而并非直接绘制在图片上。

既然有QImageWriter,当然也会有对应的读取相关的类QImageReader,敬请关注 下回分解......

相关文章

  • Qt之QImageWriter

    前言: 话不多说,自己上码 QImageWriter类为写入图像至文件或设备提供了一个独立的接口。QImageWr...

  • [转]Qt学习之样式表

    Qt学习之样式表

  • Qt设置程序图标

    说明 本文参考QT 设置程序图标、QT5.8.0 vs2013平台更改程序运行icon图标和# Qt之任务栏系统托...

  • Qt QThread类

    参考博客1:QThread详解参考博客2:Qt之线程(QThread)参考博客3:QT 多线程程序设计参考博客4:...

  • Fedora19 如何安装QT

    sudo yum install qt qt-devel qt-x11 qt-doc qt-demos qt-ex...

  • QT 反射机制的简单使用

    Qt反射前期准备 [以下内容来自博客# Qt5之反射机制(内省),转载请注意说明出处] 首先得继承于Q_Objec...

  • Qt Designer使用技巧

    编译Qt Designer 安装Qt时,选择安装源码 用Qt Creator打开C:\Qt\Qt5.5.0\5.5...

  • QCryptographicHash

    参考Qt之QCryptographicHash QCryptographicHash类--提供了生成密码散列的方法...

  • Qt 安装环境

    Qt 安装 1.1 QT下载地址 http://download.qt.io/archive/qt/ 1.1.1 ...

  • QT5.9+MSVC2015+OPENCV4.0.0搭建

    1.资源准备 QT Qt所有版本http://download.qt.io/archive/qt/我下载了QT5....

网友评论

      本文标题:Qt之QImageWriter

      本文链接:https://www.haomeiwen.com/subject/ogboxxtx.html