I am trying to load an image from QML using its source. In main.qml I have:
Image {
id: photoFiltering
fillMode: Image.PreserveAspectFit
width: parent.width
height: parent.height/2
anchors.leftMargin: 20
anchors.rightMargin: 20
anchors.bottomMargin: 20
}
and
Button{
id: filtersButtons
text: "Filter"
anchors.top: photoFiltering.bottom
anchors.horizontalCenter: photoFiltering.horizontalCenter
onClicked: ()=>{
filterController.setFilterType(filterController.Original);
var filteredImage = filterController.filterImage(photoFiltering.source);
}
}
Thus in my C++ code I ma trying to do the following:
QImage FilterController::filterImage(QString imageSource)
{
QImage image;
bool loaded = image.load(imageSource);
cout << "image laoded " << loaded << endl;
...
return image;
}
The problem is I can't simply load the image like that to get the Object QImage. What Should I do to get that image?
This is one way to retrieve a QImage from a QUrl:
Below is an ImageUtil helper class for doing the above:
This is a test of the class:
Please treat the above code as a guide only and do not expect it to stand up in a production environment. For you to do a proper job, you really need to understand: