转换画布imageURI [英] convert canvas to imageURI
本文介绍了转换画布imageURI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用开发应用的PhoneGap
(科尔多瓦
),我有尝试的画布转换为imageURI和问题它保存到SD卡。
I develop application using Phonegap
(Cordova
) and I have a problem trying to convert canvas to imageURI and to save it into sdcard.
下面是我的code:
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
在这里我错了?
and i'm got error failed 5 where i'm wrong?
推荐答案
画布不正确Android的WebView中的大多数版本的工作。
Canvas doesn't work correctly in most versions of android's webview.
要能够在画布正确地转换到一个文件在android系统的任何版本,可以使用Canvas2ImagePlugin: HTTPS ://github.com/devgeeks/Canvas2ImagePlugin
To be able to convert correctly a canvas to a file in any version of android, you can use the Canvas2ImagePlugin : https://github.com/devgeeks/Canvas2ImagePlugin
这篇关于转换画布imageURI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文