Display /provide QImage or pixel map in WebEngine view (from C++ to HTML).
-
Hi,
I want to display image (for example QImage) or any kind of pixel map from C++ to WebEngine's html.
How to do this?For example, in my html (displayed by WebEngineView) there is:
<img src="???" id="myImg">
And now I want to be able to provide this image from C++ code. So I will generate this image (with some algorithm) and I want to display it in web browser.
-
Well one way to do it is to use QWebEnginePage::runJavaScript but be careful it executes asynchronously!
http://doc.qt.io/qt-5/qtwebenginewidgets-qtwebkitportingguide.htmlthen in your javascript - find IMG element by id/class/whatever and set its contents like an embedded image e.g. change src to
src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
this is example 1x1 pixel black dot image you'll have to substitute with your own image data base64 encoded and of course change image format if you're not using png to data:image/jpg(whatever)