简体   繁体   English

我可以获取从URL加载的图像的Blob数据吗?

[英]can i get the blob data of an image loaded from an url?

I'm wondering if it's possible to get the blob data (like base64 encoded or something) of an image that's already loaded, via javascript? 我想知道是否有可能通过javascript获取已经加载的图像的blob数据(如base64编码或类似内容)?

The use case would be that I get a captcha image from a webpage into an android app. 用例是我从网页将验证码图像输入到android应用中。

You may be able to use getImageData from the Canvas API. 您可能可以使用Canvas API中的getImageData。 See https://developer.mozilla.org/En/HTML/Canvas/Pixel_manipulation_with_canvas for example. 例如,请参见https://developer.mozilla.org/En/HTML/Canvas/Pixel_manipulation_with_canvas So you can create a canvas, render the image onto it, and then use getImageData on the canvas to get the pixels. 因此,您可以创建一个画布,在其上渲染图像,然后在画布上使用getImageData获取像素。

One obstacle to this, though, is the same origin policy. 但是,与此相同的是原产地政策。 If the image that you're parsing comes from the same domain as your JavaScript, I think you're fine, but if the image comes from an external source, getImageData is going to fail due to the same origin policy. 如果您要解析的图像与JavaScript来自同一域,我认为您还可以,但是如果图像来自外部源,则由于相同的原始策略,getImageData将失败。

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

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