现在正在运作,请参阅下面的答案(https://stackoverflow.com/a/43983621/2844901)
这是我的getDrawing函数,我需要将签名从绘图保存到文件系统中的文件,我已经尝试了所有内容,但我无法在nativescript文档中获取saveToFile演示以使其正常工作。
exports.getDrawing = function(args) {
var pad = frameModule.topmost().currentPage.getViewById("drawingPad");
// then access the 'drawing' property (Bitmap on Android) of the signaturepad
var img = frameModule.topmost().currentPage.getViewById("imagesignature");
pad.getDrawing().then(function(result){
img.src = result; // <-- this shows in an image label the drawing signature
########### this part should be save the file,but I don't get any error, and it doesn't save it to a file, when tried to dump "img" ############
var img2 = imageSource.fromAsset(result);
var folder = fs.knownFolders.documents();
var path = fs.path.join(folder.path, "Test.png");
var saved = img2.saveToFile(path, "png");
});
}
答案 0 :(得分:0)
问题是,getDrawing()没有返回一个它返回一个图像的promise,所以正确的代码应该是一个NativeSource。
pad.getDrawing().then(function(result){
img.src = result;
console.log("1");
var img2 = imageSource.fromNativeSource(result);
var folder = fs.knownFolders.documents();
var path = fs.path.join(folder.path, "Test.png");
var saved = img2.saveToFile(path, "png");
console.log("saved: " + saved);
console.log("IMAGEN SRC.....");
});