Skip to main content
Inspiring
September 26, 2011
Question

cameraRoll addBitmapData file name

  • September 26, 2011
  • 3 replies
  • 4980 views

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 has been closed for replies.

3 replies

Astraport2012
Known Participant
January 19, 2012

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;

Inspiring
January 19, 2012

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

Inspiring
February 15, 2012

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. 

Astraport2012
Known Participant
January 19, 2012

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?

Inspiring
January 19, 2012

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

Astraport2012
Known Participant
January 19, 2012

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.

Inspiring
September 26, 2011

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);

 

 

                              }

Participant
June 16, 2013

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.