How to convert an image object to a binary blob

﹥>﹥吖頭↗ 提交于 2019-11-29 07:06:12

问题


Is it possible to parse an image object (<img>) in the DOM as if it had been uploaded and opened with FileReader? I am trying to use jpegmeta.js to extract EXIF metadata from JPEGs, but it needs binary strings which are returned by the FileReader.

It might be possible to use XHR to load the image from its URL and parse it with FileReader. However, this would incur a lot of overhead if every image has to be downloaded twice. Another option could have been to use the canvas, but that loses the exif data when converting.


回答1:


The general consensus seems to be summed up in this answer: Get image data in JavaScript?

So if you need the exif data, you'll need to use the XHR technique. Hopefully the browser will have the image cached, so it won't be too much of a performance hit. Otherwise the canvas technique should do the job.



来源:https://stackoverflow.com/questions/13375333/how-to-convert-an-image-object-to-a-binary-blob

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