Saturday, April 27, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 6423  / 3 Years ago, thu, may 13, 2021, 11:32:17

I'm writing an Ubuntu Touch QML app that captures and processes images from a camera device. The processing is done by a C++ plugin to which I'm passing the URL of the image.



I can successfully save images and load them from the C++ plugin, but I'd rather not have to save the images on the filesystem first, and pass the in-memory camera preview to the plugin instead.



Given the URL for the preview that I'm getting from the camera (image://camera/preview_1), I'm guessing I should be able to get a reference to the "camera" image provider and then use the requestImage() method to get the image.



However, I've not been able to figure out how to get hold of the camera image provider. Here's the code:



QString Decoder::decodeImageQML(const QUrl &imgUrl)
{
/*
* @imgUrl: URL to the camera preview. E.g. image://camera/preview_1
*/

QQmlEngine * engine;
QQuickImageProvider *imageProvider = 0;

// FIXME: this does not work, I'm not sure how to get hold of
// the image provider
imageProvider = engine->imageProvider("camera");

QImage image = imageProvider->requestImage(("preview_1", &size, QSize());

return Decoder::decodeImage(image);
}


How do I get a reference to the camera image provider?


More From » application-development

 Answers
2

You can get valid engine instance using following syntax.



QQmlEngine *engine = QQmlEngine::contextForObject(this)->engine();


And to get pointer of image provider, you can do something like following,



QQmlImageProviderBase* imageProviderBase = engine->imageProvider(item.host());
QQuickImageProvider* imageProvider = static_cast<QQuickImageProvider*>(imageProviderBase);


As QQuickImageProvider is derived from QQmlImageProviderBase, I think this cast is ok. Not sure how otherwise we can get pointer of QQuickImageProvider from engine.


[#30930] Saturday, May 15, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
istictroubli

Total Points: 306
Total Questions: 96
Total Answers: 114

Location: Sao Tome and Principe
Member since Wed, Jul 13, 2022
2 Years ago
istictroubli questions
;