Skip to main content
gondai
Participant
June 1, 2012
Answered

image path on mobile - AIR

  • June 1, 2012
  • 2 replies
  • 1503 views

I want to create image on my mobile application, after that i want to export the image. this is my code i got from other tutorial post. im using adobe flash and export it as AIR for android.

var jpgEncoder:JPGEncoder = new JPGEncoder(90);

var byteArray:ByteArray = jpgEncoder.encode( bitmapData );

// set an filename

var filename:String = "cool-wallpaper.jpg";

// get current path

var file:File = File.applicationDirectory.resolvePath( filename );

// get the native path

var wr:File = new File( file.nativePath );

// create filestream

var stream:FileStream = new FileStream();

//  open/create the file, set the filemode to write; because we are going to save

stream.open( wr , FileMode.WRITE);

// write your byteArray into the file.

stream.writeBytes ( byteArray, 0, byteArray.length );

// close the file. That’s it.

stream.close();

on my computer, the image appear on the same link as my source application. but its not working on mobile.

i tried this using android, my application is working but the image is not appear (i can't found it on any folder in my android phone).

i think i should change the path on: var filename:String = "cool-wallpaper.jpg";

but don't know what is the right path..

any one can help me about this image path issue?

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer gondai

thx for your reply, it so open my mind..

after noticed that 'applicationStorageDirectory' i do some experiments and get method called nativePath..

then i also found there is a 'userDirectory' that made me tried about nativePath method too..

i tried to trace the nativePath into text and noticed something..

so here is my code after saw the path..

// set an filename

var filename:String = File.userDirectory.nativePath+"/cool-wallpaper.jpg";

// get current path

var file:File = File.applicationStorageDirectory.resolvePath( filename );

and its working..

2 replies

User Unknow
Legend
June 1, 2012

You can't write anything to the applicationDirectory.

Use File.applicationStorageDirectory instead

Also you get path and do not wrtite to it anyting

var jpgEncoder:JPGEncoder = new JPGEncoder(90);

var byteArray:ByteArray = jpgEncoder.encode( bitmapData );

// set an filename

var filename:String = "cool-wallpaper.jpg";

// get current path

var file:File = File.applicationDirectory.resolvePath( filename );

// get the native path

var wr:File = new File( file.nativePath );

// create filestream

var stream:FileStream = new FileStream();

//  open/create the file, set the filemode to write; because we are going to save

stream.open( wr , FileMode.WRITE);

// write your byteArray into the file.

stream.writeBytes ( byteArray, 0, byteArray.length );

// close the file. That’s it.

stream.close();

Try to use:

...

// get current path

var file:File = File.applicationDocumentsDirectory.resolvePath( filename );

...

//  open/create the file, set the filemode to write; because we are going to save

stream.open( file , FileMode.WRITE);

gondai
gondaiAuthorCorrect answer
Participant
June 1, 2012

thx for your reply, it so open my mind..

after noticed that 'applicationStorageDirectory' i do some experiments and get method called nativePath..

then i also found there is a 'userDirectory' that made me tried about nativePath method too..

i tried to trace the nativePath into text and noticed something..

so here is my code after saw the path..

// set an filename

var filename:String = File.userDirectory.nativePath+"/cool-wallpaper.jpg";

// get current path

var file:File = File.applicationStorageDirectory.resolvePath( filename );

and its working..