简体   繁体   English

#Appcelerator Ti.Paint Android无法保存图像

[英]#Appcelerator Ti.Paint Android not saving image

I know the paint module is very simple, and I have been using versions of it for years. 我知道绘画模块非常简单,并且我使用它的版本已经很多年了。 Recently, (version 2.0.3), the pantView.toImage().media has stopped working. 最近(版本2.0.3),pantView.toImage()。media停止工作。 I actually us it to save a snapshot of the display so it is win.toImage().media. 实际上,我们使用它来保存显示快照,因此它是win.toImage()。media。 It gives me a 0 kb file. 它给了我一个0 kb的文件。 It detects a file, but it is empty. 它检测到一个文件,但是它是空的。 Any ideas how I can remedy the situation? 有什么想法可以解决这种情况吗?

Appcelerator SDK 5.2.0 GA Appcelerator SDK 5.2.0 GA

Ti.Paint 2.0.3 Ti.Paint 2.0.3

Android OS target 6.0.x Android OS目标6.0.x

Windows 8.1 Windows 8.1

    var sigImg = win.toImage().media; 
var filename = (Ti.App.currentWorkOrderId + "_signature.png");
    var img = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,filename);
if(img.exists){
    img.deleteFile();
}
img.write(sigImg);

Are you sure with Android 6 you have the storage permission enabled on the phone? 您确定要使用Android 6在手机上启用存储权限吗? Could it be it's not saving because it's not allowed? 难道是因为不允许而没有保存吗? Remember with Android 6 you now must ask for permissions differently than previous Android versions... 请记住,使用Android 6时,您现在必须以不同于以前的Android版本的方式来请求权限...

Ray 射线

I encountered the same problem. 我遇到了同样的问题。 Here is my code for saving the images, it works very well. 这是我保存图像的代码,效果很好。 You can inspire you.. I hope you can solve your problem ! 你可以激励你..希望你能解决你的问题!

function path(imageName) {
return Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,imageName+".png");} 


function loadImage(imageName) {
try {
     var imageFile = path(imageName);

     if(imageFile.nativePath) {
        canvas.image = imageFile.nativePath;
        console.log("LOAD !");
     }
}
catch(err) {
    console.log("ERREUR : ",err);
}}



function saveImage(imageName) {
try {
    var imageFile = path(imageName);

    imageFile.write(canvas.toImage());
    console.log("SAVE !");
  }
catch(err) {
      console.log("ERREUR : ",err);
  }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM