cordova – 如何检索保存在android系统的photolibrary中的图像?

cordova – 如何检索保存在android系统的photolibrary中的图像?,第1张

概述我正在尝试访问 Android系统的photolibrary来检索图像.我有navigator.camera.getPicture函数提供的imageURI变量.那是好的,直到那时.但后来,我想访问photolibrary并获取此图像的base64代码. 由于navigator.camera.getPicture不可能返回两个数据(imageURI和imageData),我需要稍后获取base64 我正在尝试访问 Android系统的photolibrary来检索图像.我有navigator.camera.getPicture函数提供的imageURI变量.那是好的,直到那时.但后来,我想访问photolibrary并获取此图像的base64代码.

由于navigator.camera.getPicture不可能返回两个数据(imageURI和imageData),我需要稍后获取base64信息.这是我试图使用的代码,查看phoneGap的“文件”文档,但它不起作用.

它停在“fileSystem.root.getfile”调用 – (错误回调中的错误:file4 = TypeError:表达式’evt.target'[undefined]的结果不是对象.在file:/// androID_asset / www / phonegap- 1.3.0.Js:717)

谁能帮帮我?谢谢.

function base64(imageURI) { alert(imageURI); document.addEventListener("deviceready",onDeviceReady); function onDeviceReady() {     window.requestfileSystem(LocalfileSystem.PERSISTENT,gotFS,fail);} function gotFS(fileSystem) {     alert("filesystem");             //Next line causes error. Perhaps imageURI is not a valID path?     fileSystem.root.getfile(**imageURI**,null,gotfileEntry,fail);} function gotfileEntry(fileEntry) {     alert("gotfileentry");     fileEntry.file(gotfile,fail);} function gotfile(file){     alert("got file");     readDataUrl(file);} function readDataUrl(file) {     alert("readDataURL");     var reader = new fileReader();     reader.onloadend = function(evt) {         console.log("Read as data URL");         alert(evt.target.result);         };     reader.readAsDataURL(file); } function fail(evt) {     console.log(evt.target.error.code);}}
解决方法 好的,第一个问题是失败函数返回的对象没有您尝试访问的属性.要查看错误对象中的内容,请尝试以下 *** 作:

function fail(evt) {                 alert("there was an error: " + JsON.stringify(evt));            }

让我们知道它产生了什么……

总结

以上是内存溢出为你收集整理的cordova – 如何检索保存在android系统的photolibrary中的图像?全部内容,希望文章能够帮你解决cordova – 如何检索保存在android系统的photolibrary中的图像?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1001966.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存