开发者

How to display a QImage in QWebKit?

Is there any way to display a QImage (in memory, not on filesystem) in a QWebFrame without writing the ima开发者_运维问答ge out to a temporary file?


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.


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()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜