save image in a directory in applicationStorageDir

2019-02-25 21:24发布

I was trying to save an imagefile to a directory in applicationStorageDirectory of my air project. Created the directory first

 var imageDirectory:File = File.applicationStorageDirectory.resolvePath("vispics");

   if (imageDirectory.exists)
   {
       Alert.show("Directory Already Exists");

   }
   else {
       imageDirectory.createDirectory();
       Alert.show(imageDirectory.nativePath);
   }

The next part is saving image from my cam right now it saves to the applicationStorageDirectory. Here is how i do it

     var randInt:int = Math.random() * (99999 - 1001) + 1001;
      var randStr:String = randInt.toString();
      var filename:String = ""+randStr+".jpg";


        var file:File = File.applicationStorageDirectory.resolvePath( filename );
        var wr:File = new File( file.nativePath );
    var stream:FileStream = new FileStream();
        stream.open( wr , FileMode.WRITE);
        stream.writeBytes ( imageData, 0,imageData.length );
        stream.close();

Is there a way that i can store the image in my "vispics" directory? Thanks in advance.

1条回答
Juvenile、少年°
2楼-- · 2019-02-25 22:08

Try:

var file:File = File.applicationStorageDirectory.resolvePath("vispics/" + filename);
查看更多
登录 后发表回答