How to display a QImage in QWebKit?

风格不统一 提交于 2019-12-13 03:30:54

问题


Is there any way to display a QImage (in memory, not on filesystem) in a QWebFrame without writing the image out to a temporary file?


回答1:


One option might be using the data URI scheme. You basically base64 encode your picture and write the complete data into the URL. For example:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC

WebKit should support these URIs either directly, or as part of a HTML source code, like

<img src="data:image/png;base64,blaBLABLA" />

Be aware: if your image is big, you might be running into some constraints. Usually this used more for small stuff like icons.




回答2:


Damn. Steffen beat me to it! :)

To add, you could convert to base 64 by saving the image to a QBuffer(&byteArray) and then saying byteArray.toBase64()



来源:https://stackoverflow.com/questions/4394048/how-to-display-a-qimage-in-qwebkit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!