我使用Phonegap (Cordova)开发应用程序,在将画布转换为imageURI并将其保存到sdcard时遇到了问题。
这是我的代码:
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,我错了?
发布于 2014-04-14 10:00:00
在android的大多数版本的webview中,Canvas都不能正常工作。
要正确地将画布转换为任意版本的android中的文件,可以使用Canvas2ImagePlugin:https://github.com/devgeeks/Canvas2ImagePlugin。
https://stackoverflow.com/questions/23043014
复制相似问题