Use QImageReader so images are loaded in correct orientation

This commit is contained in:
Anton Thomasson 2022-07-06 20:31:09 +02:00
parent 8ea54769c5
commit 95ef563230

View file

@ -120,13 +120,17 @@ try {
} }
else if(targetFormat == Mimer::RBMP) else if(targetFormat == Mimer::RBMP)
{ {
QImage inImage; QImageReader reader(filename);
reader.setAutoTransform(true);
QImage inImage = reader.read();
QBuffer buf; QBuffer buf;
if(!inImage.load(filename))
if(inImage.isNull())
{ {
qDebug() << "failed to load"; qDebug() << "failed to load";
throw ConvertFailedException(tr("Failed to load image")); throw ConvertFailedException(tr("Failed to load image"));
} }
// TODO: calculate paper width minus margins // TODO: calculate paper width minus margins
// (depends on understanding/parsing custom paper sizes) // (depends on understanding/parsing custom paper sizes)
int width = 576; int width = 576;
@ -147,13 +151,17 @@ try {
} }
else else
{ {
QImage inImage; QImageReader reader(filename);
reader.setAutoTransform(true);
QImage inImage = reader.read();
QBuffer buf; QBuffer buf;
if(!inImage.load(filename))
if(inImage.isNull())
{ {
qDebug() << "failed to load"; qDebug() << "failed to load";
throw ConvertFailedException(tr("Failed to load image")); throw ConvertFailedException(tr("Failed to load image"));
} }
buf.open(QIODevice::ReadWrite); buf.open(QIODevice::ReadWrite);
inImage.save(&buf, imageFormat.toStdString().c_str()); inImage.save(&buf, imageFormat.toStdString().c_str());
buf.seek(0); buf.seek(0);
@ -314,7 +322,11 @@ try {
} }
else else
{ {
if(!inImage.load(filename)) QImageReader reader(filename);
reader.setAutoTransform(true);
inImage = reader.read();
if(inImage.isNull())
{ {
qDebug() << "failed to load"; qDebug() << "failed to load";
throw ConvertFailedException(tr("Failed to load image")); throw ConvertFailedException(tr("Failed to load image"));