我使用Phonegap
(Cordova
)开发应用程序,我在尝试将canvas转换为imageURI并将其保存到SD卡时遇到问题。
这是我的代码:
function saveCanvasAsImage(imageURI) {
var gotFileEntry = function(fileEntry) {
var gotFileSystem = function(fileSystem) {
var d = new Date();
var n = d.getTime();
// copy the file
fileEntry.moveTo(fileSystem.root.feelathome, n + ".jpg", null, null);
};
// get file system to copy or move image file to
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem, fsFail);
alert("Image Capture Success");
};
//resolve file system for image
window.resolveLocalFileSystemURI(document.getElementById("canvas").toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/, ""), gotFileEntry, fsFail);
}
//file system fail
function fsFail(error) {
alert("failed with error code: " + error.code);
}
我错误失败5 我哪里错了?
答案 0 :(得分:0)
在大多数Android版webview中,Canvas无法正常工作。
为了能够将画布正确转换为任何版本的android中的文件,您可以使用Canvas2ImagePlugin:https://github.com/devgeeks/Canvas2ImagePlugin