Not yet rated
Tags:



Problem

I want to be able to access image metadata for images on my device.

Solution

Load media promise using one of available EXIF parsing libraries.

Detailed explanation

Flash Builder Project with solution

Compiled project for Android

CameraUI and  CameraRoll allows to get  MediaPromise object that can be loaded as bytes:

private function useCameraRoll():void
        {
    var cameraRoll:CameraRoll = new CameraRoll();
    cameraRoll.addEventListener(MediaEvent.SELECT, cameraRoll_selectHandler);
    cameraRoll.addEventListener(ErrorEvent.ERROR, some_errorHandler);
    cameraRoll.browseForImage();
}

private function cameraRoll_selectHandler(event:MediaEvent):void
{
    showEXIFFromPromise(event.data);
}

private function useCameraUI():void
{
    var cameraUI:CameraUI = new CameraUI();
    cameraUI.addEventListener(MediaEvent.COMPLETE, cameraUI_completeHandler);
    cameraUI.addEventListener(ErrorEvent.ERROR, some_errorHandler);
    cameraUI.launch(MediaType.IMAGE);
}

private function cameraUI_completeHandler(event:MediaEvent):void
{
    showEXIFFromPromise(event.data);
}
  
 
Here is how to get the  ExifInfo object:
private function showEXIFFromPromise(data:MediaPromise):void
{
    if (data.isAsync)
    {
        data.addEventListener(Event.COMPLETE, readDataSource);
        data.addEventListener(IOErrorEvent.IO_ERROR, some_errorHandler);
        dataSource = data.open();
    }
    else
    {
        dataSource = data.open();
        readDataSource();
    }
}

private function readDataSource(... args):void
{
    var byteArray:ByteArray = new ByteArray();
    dataSource.readBytes(byteArray, 0, dataSource.bytesAvailable);
    var exifInfo:ExifInfo = new ExifInfo(byteArray);
    showEXIFInf1o(exifInfo);
}

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes