Skip to main content
Inspiring
Sep 26, 2011 1:18 PM UTC
Question

cameraRoll addBitmapData file name

How do I get the file name of the image created by addBitmapData?

I'm capturing an image of a multiTouch drawing with this ...

   var cameraRoll:CameraRoll = new CameraRoll(); 

                                        var bitmapData:BitmapData = new BitmapData(bc.width, bc.height);

                                        bitmapData.draw(bc);

                                        cameraRoll.addBitmapData(bitmapData);

When addBitmapData is complete, I need to receive the file name back so I can display back the resulting captured image.

Researching the docs, it doesn't look like there is a complete event for addBitmapData.

Thanks,

Don

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

13 replies

Astraport2012
Known Participant
Jan 19, 2012 4:28 PM UTC

Add one line and all work fine! Thank you Don Kerr!

var files:Array = new Array();

                                        files = cameraDir.getDirectoryListing();

                                        files.sortOn("creationDate", Array.NUMERIC); // sorting array

                                        var newFile:File = new File();

                                        newFile = files[files.length-1] as File;

Translate
Inspiring
Jan 19, 2012 4:53 PM UTC

Interesting that you had to sort.  Were your file defaulting to DESC order, thus the last pic was was the top?  What device?  Might be a device-specific thing.

Glad it helped.

Don

Translate
Inspiring
Feb 15, 2012 11:08 PM UTC

Any reason the share image wouldn't work in Flash Pro swf compiled with ADT?  I have the toast from the same extension working without issue.  I have the URL coming back accurately but when the AndroidExtensions.shareImage(imgPath, "Share:"); is called, nothing happens. 

Translate
Astraport2012
Known Participant
Jan 19, 2012 11:54 AM UTC

I have the same problem and can not find a solution. Created image is stored in the camera roll, but how to get the link (path) to the saved image?

Translate
Inspiring
Jan 19, 2012 12:37 PM UTC

onCrComplete() above gets the url to newest image in the roll. newFile.url .  This has been working great for me.

Translate
Astraport2012
Known Participant
Jan 19, 2012 2:00 PM UTC

This is not working for me. I do so.

protected function saveCameraRoll(event:MouseEvent):void{

  var cr:CameraRoll = new CameraRoll();

                                        cr.addEventListener(Event.COMPLETE, onComplite);

                                        cr.addBitmapData(bitmapData);

                              }

                              protected function onComplite(event:Event):void

                              {

                                        var cDir:String = File.documentsDirectory.resolvePath("DCIM/Camera/").nativePath;

                                        var cameraDir:File = new File(cDir);

                                        var files:Array = cameraDir.getDirectoryListing();

 

                                        var newFile:File = new File();

                                        newFile = files[files.length-1];

 

                                        var newPhoto:Object = new Object();

                                        newPhoto.fileName = newFile.name;

                                        newPhoto.url = newFile.url;

 

                                        navigator.pushView(views.ShareImageView, newPhoto);

                              }

In next view I want to display created image and send it by mail.

[Bindable]

                              protected var imgPath:String;

                              protected var loader:Loader;

protected function shareBtn_clickHandler(event:MouseEvent):void

                              {

                                        AndroidExtensions.shareImage(imgPath, "Share:");

                              }

 

                              protected function onCreationCompleteHandler(event:FlexEvent):void

                              {

 

                                        if(!loader)

                                        {

                                                  loader = new Loader();

                                                  loader.load(new URLRequest(data.url));

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

                                        }

                              }

 

                              protected function onLoadComplete(e:Event) : void

                              {

                                        imgPath = data.url;

                                        img.source = loader.content;

                                        shareBtn.enabled = true;

                              }

<s:BitmapImage id="img" width="100%" height="100%" fillMode="scale" scaleMode="letterbox"/>

<s:Button id="shareBtn" label="Share" click="shareBtn_clickHandler(event)" enabled="false"/>

As a result, display another image which is obtained the latter with the camera.

And when i send the mail to the link data.url() did not attach anything. If i select an image from the gallery by cr.browseForImage() it works fine.

Translate
Inspiring
Sep 26, 2011 5:15 PM UTC

For now, I decided to just grab the last pic added to the roll.

But, if there is a better way, please let me know.

code below if anyone else has this need:

private function captureDrawing():void {

 

                                        var cameraRoll:CameraRoll = new CameraRoll(); 

                                        var bitmapData:BitmapData = new BitmapData(bc.width, bc.height);

                                        bitmapData.draw(bc);

                                        cameraRoll.addBitmapData(bitmapData);

 

                                        cameraRoll.addEventListener(Event.COMPLETE, onCrComplete);

                              }

 

                              protected function onCrComplete(event:Event):void

                              {

  ///mnt/sdcard/DCIM/Camera/

                                        var cDir:String = File.documentsDirectory.resolvePath("DCIM/Camera/").nativePath;

 

                                        var cameraDir:File = new File(cDir);

 

                                        var files:Array = cameraDir.getDirectoryListing();

 

                                        var newFile:File = new File();

                                        newFile = files[files.length-1];

 

                                        var newPhoto:Object = new Object();

                                        newPhoto.fileName = newFile.name;

                                        newPhoto.url = newFile.url;

 

photosDP.addItemAt(newPhoto,0);

 

 

                              }

Translate
Participant
Jun 16, 2013 7:56 AM UTC

Hi all,

the following code I was used get something wrong:

var cDir:String = File.documentsDirectory.resolvePath("DCIM/Camera").nativePath;

var cameraDir:File = new File(cDir);

cDir becomes "/var/mobile/Applications/E6C07DFA-D52E-4DDB-8C34-4D190F984457/Documents/DCIM/Camera",

but I got the error: Error #3003: File or directory does not exist.

anyone knows why?

thanks~

BR,

Yeats.

Translate