• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
1

cameraRoll addBitmapData file name

Engaged ,
Sep 26, 2011 Sep 26, 2011

Copy link to clipboard

Copied

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

TOPICS
Development

Views

4.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 26, 2011 Sep 26, 2011

Copy link to clipboard

Copied

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

 

 

                              }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 16, 2013 Jun 16, 2013

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 19, 2012 Jan 19, 2012

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 19, 2012 Jan 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 19, 2012 Jan 19, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 19, 2012 Jan 19, 2012

Copy link to clipboard

Copied

What specifically isn't working?  Your onComplite looks ok.  Set a breakpoint after newFile.  What is newFile.url value?  What is cDir value?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 19, 2012 Jan 19, 2012

Copy link to clipboard

Copied

If I save the image in the gallery with CameraRoll using the code above, then I get the link to this image: newPhoto.url = newFile.url; // file:///mnt/sdcard/DCIM/Camera/20120119_112543.jpg 

But it is quite another picture. My right image, which I saved with help cr.addBitmapData(bitmapData), have another link - /mnt/sdcard/DCIM/Camera/132700152384.jpg.

I get this link if i call browseForImage() for my image. The problem is not in the path and that created images are missing in the files:Array

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 19, 2012 Jan 19, 2012

Copy link to clipboard

Copied

Very strange...

All my images created with addBitmapData displayed in the gallery, in the file system manager, but they do not come in an array getDirectoryListing (), they are not there.

No matter how much I create new images, the array length remains the same. Miracles.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 19, 2012 Jan 19, 2012

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 19, 2012 Jan 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 15, 2012 Feb 15, 2012

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 16, 2012 Feb 16, 2012

Copy link to clipboard

Copied

I can't even seem to get the simplest example from that extension to work.  The toast from the same extension works without issue but share mechanism doesn't.  Not sure if there is something that makes it only work on Flex...

AndroidExtensions.shareText(“My Subject”, “My Text”, “Share:”);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 16, 2012 Feb 16, 2012

Copy link to clipboard

Copied

I figured out my error, didnt remove the old ANE from the compile directory when updated the ANE that supported image sharing.  Only issue I have now is that I can share with every servcie except gmail.  It shows it as attached but never sends it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines