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
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);
}
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(Ev ent.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.
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
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;
North America
Europe, Middle East and Africa
Asia Pacific