Adding Images and Video
Adding BitmapData
With the standard CameraRoll
implementation you can easily add a BitmapData
reference to the camera roll, using the addBitmapData
function.
This functionality is also duplicated in this extension:
var bd:BitmapData = ...;
CameraRollExtended.service.addBitmapData( bd );
We have added some additional options around this function that allow you to control the format, quality and filename.
CameraRollExtended.service.addBitmapData( bd, "png", 1, "plane.png" );
The format can either be "png"
or "jpg"
and the quality should be a number between 0 (lowest quality) and 1 (highest quality). The default is "jpg"
at 0.8
The filename is used as the name of the file on Android.
Adding files
You may have image files that you wish to add to the camera roll without have to load the bitmap data into memory, and you may also have video content that you want to add to the camera roll.
To achieve this you can use the addFile()
function, passing the File
reference to the file you wish to add to the camera roll.
var video:File = File.applicationDirectory.resolvePath("assets/video.mp4");
var success:Boolean = CameraRollExtended.service.addFile( video, Asset.VIDEO );
If the functionality is not supported or there was an error initiating the transfer to the camera roll then this function may return false
. If it returns true
, the process was started successfully and you can expect one of the following events:
CameraRollExtendedEvent.ADD_FILE_COMPLETE
: When the file was successfully transferred to the camera roll;CameraRollExtendedEvent.ADD_FILE_ERROR
: If there was an error.
CameraRollExtended.service.addEventListener( CameraRollExtendedEvent.ADD_FILE_COMPLETE, addFile_completeHandler );
CameraRollExtended.service.addEventListener( CameraRollExtendedEvent.ADD_FILE_ERROR, addFile_errorHandler );
CameraRollExtended.service.addFile( video, Asset.VIDEO );
function addFile_completeHandler( event:CameraRollExtendedEvent ):void
{
trace( "addFile_completeHandler()" );
}
function addFile_errorHandler( event:CameraRollExtendedEvent ):void
{
trace( "addFile_errorHandler(): ["+event.errorCode+"] :: " + event.message );
}
Android
If you are supporting Android < API v28 then you will need to ensure you add the WRITE_EXTERNAL_FILES
permission to your application.
If you are using apm
all you can generate a custom configuration manifest and then add the additional permission to that.
apm generate config android
Open the file generated at config/android/AndroidManfiest.xml
and ensure you add the following line:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
Then regenerate your application descriptor:
apm generate app-descriptor src/MyApp-app.xml
If you are manually managing your application descriptor (and manifest additions) then you will need to add the following line to the <manifestAdditions>
tag in your application descriptor:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />