简体   繁体   中英

#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. I actually us it to save a snapshot of the display so it is win.toImage().media. It gives me a 0 kb file. It detects a file, but it is empty. Any ideas how I can remedy the situation?

Appcelerator SDK 5.2.0 GA

Ti.Paint 2.0.3

Android OS target 6.0.x

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? 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...

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);
  }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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