Use QImageReader::setAutoTransform() in examples.

Change-Id: If80616d680f1aa6c9d5cd1a4080710e5ad67d603
Reviewed-by: Rainer Keller <rainer.keller@theqtcompany.com>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2015-07-12 23:47:20 +02:00 committed by Friedemann Kleint
parent f1f9489d08
commit 0d81316dcc
3 changed files with 14 additions and 5 deletions

View File

@ -124,10 +124,16 @@
\snippet widgets/imageviewer/imageviewer.cpp 2
In the \c loadFile() function, we check if the file's
format is an image format by constructing a QImage which tries to
load the image from the file. If the constructor returns a null
image, we use a QMessageBox to alert the user.
In the \c loadFile() function, we instantiate a QImageReader
and enable automatic transformations by calling
QImageReader::setAutoTransform(). For files in JPEG format,
this ensures that portrait mode images of digital cameras are shown
correctly by applying the appropriate orientation read from the
EXIF meta data stored in the image file.
We then load the image using QImageReader::read(). If this returns
a null image, indicating that the file is not an image file,
we use a QMessageBox to alert the user.
The QMessageBox class provides a modal dialog with a short
message, an icon, and some buttons. As with QFileDialog the

View File

@ -202,6 +202,7 @@ QImage ImageWidget::loadImage(const QString &fileName)
{
qDebug() << position << files << fileName;
QImageReader reader(fileName);
reader.setAutoTransform(true);
qCDebug(lcExample) << "loading" << QDir::toNativeSeparators(fileName) << position << '/' << files.size();
if (!reader.canRead()) {
qCWarning(lcExample) << QDir::toNativeSeparators(fileName) << ": can't load image";

View File

@ -69,7 +69,9 @@ ImageViewer::ImageViewer()
bool ImageViewer::loadFile(const QString &fileName)
{
QImage image(fileName);
QImageReader reader(fileName);
reader.setAutoTransform(true);
const QImage image = reader.read();
if (image.isNull()) {
QMessageBox::information(this, QGuiApplication::applicationDisplayName(),
tr("Cannot load %1.").arg(QDir::toNativeSeparators(fileName)));