多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] ## 概述 ## 示例 ### 设置写入格式 ``` QImageWriter writer; writer.setFormat("png"); // 同writer.setFormat("PNG"); ``` ### 写入信息 ``` QImageWriter writer(fileName); if (writer.supportsOption(QImageIOHandler::Description)) writer.setText("Author", "Mr Wang"); ``` 不同的图像格式支持不同的选项。调用此函数,可以确定当前格式是否支持一个特定的选项 ### 显示支持的类型和 MIME ``` QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats(); QList<QByteArray> mimeTypes = QImageWriter::supportedMimeTypes(); ``` ``` // imageFormats : ("bmp", "cur", "dds", "icns", "ico", "jp2", "jpeg", "jpg", "pbm", "pgm", "png", "ppm", "tif", "tiff", "wbmp", "webp", "xbm", "xpm") // mimeTypes : ("", "image/bmp", "image/jp2", "image/jpeg", "image/png", "image/tiff", "image/vnd.microsoft.icon", "image/vnd.wap.wbmp", "image/webp", "image/x-dds", "image/x-icns", "image/x-portable-bitmap", "image/x-portable-graymap", "image/x-portable-pixmap", "image/x-xbitmap", "image/x-xpixmap") ``` ### 写入图片 ``` // 源图像 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; } ```