首页| 论坛| 消息

标题:QImage,QPixmap加载照片图像,切记处理拍摄方向
作者:shixingya
日期:2018-10-19 09:51
内容:

QImage,QPixmap加载照片图像,切记处理拍摄方向

现在数码相机拍摄图片都有拍摄方向,水平、垂直拍摄,拍摄后,图像内容会保存相应的信息,我们可以获取这些信息,对图像做展示,不然你会发现,一张图片,90度拍摄后,QImage加载会发生90度旋转,我测试如果不做处理,html5的image标签,python的CV2模块加载图片,都会发现图片方向被旋转90度。再Qt中 可以用如下方式来修正图像方向
QImageReader reader(path);
reader.setAutoTransform(true);
const QImage newImage = reader.read();
QImageIOHandler::Transformations transformation;
if (newImage.isNull()) {
QMessageBox::information(nullptr, QGuiApplication::applicationDisplayName(),
tr("Cannot load %1: %2")
.arg(QDir::toNativeSeparators(path), reader.errorString()));
return;
}
else
{
transformation = reader.transformation();
qDebug()

回复 发表
主题 版块