Skip to main content
Inspiring
February 26, 2013
Question

Loading a list of images from CameraRoll or the device file system

  • February 26, 2013
  • 2 replies
  • 641 views

Hi,

since i didn't find a satisfying answer to that question i would like to ask in this discussion group.

This is what i need in a new mobile app for Android and iOS devices: A user should be able to "import" one or several photos from CameraRoll (one would be ok because it should be possible to add text and a name by the user between selecting and import). Importing means that unique characteristica (id, name, path, ...) of the photos should be stored in the app's database for later use.

After importing the images the user should be able to see these images as thumbnails on an overview page in the app itself, i.e. the previously imported photos should be listed there where the user can edit, delete them there.

Now the questions:

  • Is such an import of several images from CameraRoll possible with AIR 3.6 or planned in later releases ?
  • Is a listing of imported photos on an overview page in the app possible (i.e. loading them with the info i got when importing from CameraRoll) ?
  • Is loading photos directly from file system (CameraRoll album directories) possible if the photo's paths would be available ?

So far all my tests were negative. When debugging a test app i didn't get any image information that could be used for later loading or identifying again a photo from CameraRoll. Also the properties in MediaPromise are all null after selecting one photo.

It also seems that there isn't any ANE around that could help me.

Any tips or links are appreciated. Thank you!

valley

This topic has been closed for replies.

2 replies

Zeloslaw
Known Participant
February 26, 2013

Hi,

My Callout gallery:

<s:Callout xmlns:fx="http://ns.adobe.com/mxml/2009"

           xmlns:s="library://ns.adobe.com/flex/spark"

           contentBackgroundAppearance="none"

           horizontalPosition="start"

           verticalPosition="after"

           creationComplete="creationCompleteHandler()">

    <fx:Script>

        <![CDATA[

            import spark.components.Image;

            private var loader:Loader;

            private var assetsFile:File = File.applicationDirectory.resolvePath("gallery");

            private var imgJPGArr:Array;

            private var imageLoop:Number = 0;

            private var clickEnabled:Boolean = false;

            private function imagesJPGFilter( directory:File ):Array

            {

                var images:Array = new Array();

                if (directory.isDirectory)

                {

                    var files:Array = directory.getDirectoryListing();

                    for (var i:int = 0; i < files.length; i++)

                    {

                        if (!files.isDirectory)

                        {

                            //count += recursiveDirectoryListing( files );

                            //images

                            if(files.extension == "jpg" || files.extension == "JPG" ||

                                files.extension == "jpeg" || files.extension == "JPEG")

                            {

                                //trace(files.url);

                                images.push( files );

                            }

                        }

                    }

                }

                return images;

            }

            private function creationCompleteHandler():void

            {

                loader = new Loader();

                loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoader);

                imgJPGArr = imagesJPGFilter( assetsFile );

                loadImages( imageLoop );

            }

            private function loadImages( imageLoop:Number ):void

            {   

                loader.load(new URLRequest( imgJPGArr[ imageLoop ].url ));

            }

            private function imgLoader(event:Event):void

            {

                var myImg:Image = new Image();

                myImg.width = 110;

                myImg.height = 150;

                myImg.smooth = true;

                myImg.scaleMode = "letterbox";

                myImg.source = event.target.content;

                //var resultData:Object = new Object();

                //resultData.iconIMG = myImg;

                //resultData.orginIMG = imgJPGArr[ imageLoop ];

                var functionDoIt:Function = addDeleteHandler( event.target.content );

                myImg.addEventListener(MouseEvent.CLICK, functionDoIt);

                gallContainer.addElement( myImg );

                //myImg=null;

                if(imageLoop < imgJPGArr.length-1)

                {

                    //trace("wlazlo");

                    imageLoop++;

                    loadImages( imageLoop );

                }

                else

                {

                    loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, imgLoader);

                    loader=null; assetsFile=null; imgJPGArr=null;

                    clickEnabled = true;

                    bi.visible = false;

                }

            }

            private function addDeleteHandler(imgJPG:Bitmap):Function

            {

                return function(event:MouseEvent=null):void

                {

                    if(clickEnabled == true)

                    {

                        if(imgJPG)

                        {

                            close(true, imgJPG);

                        }

                    }

                }

            }

        ]]>

    </fx:Script>

    <fx:Declarations>

    </fx:Declarations>

    <s:Scroller focusEnabled="false" hasFocusableChildren="true" width="500" height="600" horizontalScrollPolicy="off">

        <s:TileGroup id="gallContainer" horizontalGap="5" verticalGap="5" paddingTop="10" paddingLeft="10" paddingRight="10" cacheAsBitmap="true" opaqueBackground="0xf2f2f2">

        </s:TileGroup>

    </s:Scroller>

    <s:BusyIndicator id="bi" horizontalCenter="0" rotationInterval="100" symbolColor="black"

                     verticalCenter="0"/>

</s:Callout>

unfortunately very slow if there are no icons.

valley tAuthor
Inspiring
February 26, 2013

Thank you, but "gallery" is a directory in your app directory. I need access to the CameraRoll directory (something like /var/mobile/Media/DCIM).

I don't think that will work with your approach - or i just haven't found the correct path where the CameraRoll photos are stored.