前言:
话不多说,自己上码
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,敬请关注 下回分解......
网友评论