简体   繁体   English

如何将浏览器中加载的图像转换为 base64 字符串?

[英]How convert loaded Image in browser to base64 string?

I loaded a url in qml WebView , In this page there is an image and is displaying with WebView but when I get the source of the page with `document.documentElement.innerHTML',I see the image tag like this:我在 qml WebView加载了一个 url ,在这个页面中有一个图像并且正在用WebView显示但是当我用`document.documentElement.innerHTML'获取页面的源时,我看到这样的图像标签:


<td class="labelColumn">
<img class="g-Image" title="Captha Image" src="https://website.com/user-account/gwt/entrypoint/registeruser.captcha" style="height: 35px; width: 130px;">
</td>

But the WebView is displaying this image and I my question is that I should be able to get the image in base64 string or the path of it.但是WebView正在显示此图像,我的问题是我应该能够以 base64 字符串或其路径获取图像。 How can I find the image?我怎样才能找到图像?

When I run document.images[0].src I will get https://website.com/user-account/gwt/entrypoint/registeruser.captcha .当我运行document.images[0].src我会得到https://website.com/user-account/gwt/entrypoint/registeruser.captcha

I want the content of the image ,It may be base64 string or the path or... .我想要图像的内容,它可能是 base64 字符串或路径或...。

Use the HTMl5 <canvas> element.使用 HTMl5 <canvas>元素。

Load the image inside of the canvas and then use the toDataURL() method/function.在画布内加载图像,然后使用toDataURL()方法/函数。 That should give you the base64 output.这应该给你 base64 输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM