我正在使用英特尔XDK为Android构建HTML5应用程序。我尝试在Canvas中加载一个本地存储在设备上的图像,在应用程序临时文件系统中。
我的基础是 Open local image in canvas :
this.dirEntry.getFile(imagePath, {}, function (fileEntry) {
fileEntry.file(function (file) {
console.log("Loading " + file.fullPath +" to canvas");
var ctx = container.getContext('2d');
var img = new Image();
var url = window.URL || window.webkitURL;
var src = url.createObjectURL(file);
img.onload = function () {
ctx.drawImage(img, 0, 0);
url.revokeObjectURL(src);
}
img.src = src;
});
}, function (evt) {
console.log(evt);
});
当我使用IntelXDK和Weirn进行测试时,我得到:
Loading file:///storage/emulated/0/Android/data/com.intel.html5tools.apppreview/cache/repositories/00001/summary.jpg to canvas
processMessage failed: Error: TypeError: Type error
processMessage failed: Stack: TypeError: Type error
at load (file:///data/data/com.intel.html5tools.apppreview/files/appmobicache/nE5zi-ycD6TAzOFeh0Y3aXzMHLix6sA22cSUzZ6e3lo/4.0.0/js/app.js:248:27)
at file:///data/data/com.intel.html5tools.apppreview/files/appmobicache/nE5zi-ycD6TAzOFeh0Y3aXzMHLix6sA22cSUzZ6e3lo/4.0.0/js/app.js:271:21
at win (file:///android_asset/www/plugins/org.apache.cordova.file/www/FileEntry.js:71:9)
at Object.cordova.callbackFromNative (file:///data/data/com.intel.html5tools.apppreview/files/appmobicache/nE5zi-ycD6TAzOFeh0Y3aXzMHLix6sA22cSUzZ6e3lo/4.0.0/cordova.js:292:54)
at processMessage (file:///data/data/com.intel.html5tools.apppreview/files/appmobicache/nE5zi-ycD6TAzOFeh0Y3aXzMHLix6sA22cSUzZ6e3lo/4.0.0/cordova.js:1039:21)
at Function.androidExec.processMessages (file:///data/data/com.intel.html5tools.apppreview/files/appmobicache/nE5zi-ycD6TAzOFeh0Y3aXzMHLix6sA22cSUzZ6e3lo/4.0.0/cordova.js:1076:13)
at pollOnce (file:///data/data/com.intel.html5tools.apppreview/files/appmobicache/nE5zi-ycD6TAzOFeh0Y3aXzMHLix6sA22cSUzZ6e3lo/4.0.0/cordova.js:944:17)
at pollOnceFromOnlineEvent (file:///data/data/com.intel.html5tools.apppreview/files/appmobicache/nE5zi-ycD6TAzOFeh0Y3aXzMHLix6sA22cSUzZ6e3lo/4.0.0/cordova.js:939:5)
processMessage failed: Message: S01 File1974092051 {"lastModifiedDate":1413544852000,"fullPath":"file:\/\/\/storage\/emulated\/0\/Android\/data\/com.intel.html5tools.apppreview\/cache\/repositories\/00001\/summary.jpg","type":"image\/jpeg","name":"summary.jpg","size":91793}
当我直接测试应用程序(因此在设备上构建和部署)(并使用Weirn)时,我得到:
Loading [object Object] to canvas
processMessage failed: Error: TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.
processMessage failed: Stack: TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.
at TypeError (native)
at load (file:///android_asset/www/js/app.js:248:27)
at file:///android_asset/www/js/app.js:271:21
at win (file:///android_asset/www/plugins/org.apache.cordova.file/www/FileEntry.js:72:9)
at Object.cordova.callbackFromNative (file:///android_asset/www/cordova.js:292:54)
at processMessage (file:///android_asset/www/cordova.js:1039:21)
at Function.androidExec.processMessages (file:///android_asset/www/cordova.js:1076:13)
at pollOnce (file:///android_asset/www/cordova.js:944:17)
at pollOnceFromOnlineEvent (file:///android_asset/www/cordova.js:939:5)
processMessage failed: Message: S01 File1409319454 {"lastModifiedDate":1413530713000,"fullPath":"\/repositories\/00001\/summary.jpg","type":"image\/jpeg","name":"summary.jpg","size":91793}
一个想法是什么?