-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyimageprovider.cpp
54 lines (44 loc) · 1.38 KB
/
myimageprovider.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "myimageprovider.h"
#include <QImageReader>
MyImageProvider::MyImageProvider(QQmlImageProviderBase::ImageType type,
QQmlImageProviderBase::Flags flags)
: QQuickImageProvider(type,flags)
{
}
MyImageProvider::~MyImageProvider()
{
}
QImage MyImageProvider::requestImage(const QString &id,
QSize *size, const QSize &requestedSize)
{
// qDebug() << "image id ==" << id;
QImageReader imgReader(id);
imgReader.setAutoTransform(true);
QImage initImage = imgReader.read();
if(initImage.isNull()) { // error in getting image
qDebug() << "Image read error:" << imgReader.errorString();
initImage = QImage(requestedSize,QImage::Format_ARGB32);
initImage.fill(Qt::lightGray);
}
QImage retVal;
if(requestedSize.isValid()) {
retVal = initImage.scaled(requestedSize, Qt::KeepAspectRatio);
} else {
retVal = initImage;
}
*size = retVal.size();
return retVal;
}
QPixmap MyImageProvider::requestPixmap(const QString &id,
QSize *size, const QSize &requestedSize)
{
QPixmap initImage(id);
QPixmap retVal;
if(requestedSize.isValid()) {
retVal = initImage.scaled(requestedSize, Qt::KeepAspectRatio);
} else {
retVal = initImage;
}
*size = retVal.size();
return retVal;
}