Android 保存相机拍摄的JPG图像

Android 保存相机拍摄的JPG图像,android,camera,air,actionscript-3,Android,Camera,Air,Actionscript 3,我正在使用下面的代码打开Android设备的摄像头。 如何保存此相机拍摄的JPG图像? 我应该将什么代码/按钮添加到编程AS3/AIR中 public class Test_Cam extends Sprite { private var cam: Camera; public function Test_Cam() { cam = Camera.getCamera(); connectCamera(); function connectCamera(): void { var vid: Vid

我正在使用下面的代码打开Android设备的摄像头。 如何保存此相机拍摄的JPG图像? 我应该将什么代码/按钮添加到编程AS3/AIR中

public class Test_Cam extends Sprite {
private var cam: Camera;
public function Test_Cam() {
cam = Camera.getCamera();
connectCamera();
function connectCamera(): void {
var vid: Video = new Video(cam.width, cam.height);
vid.x = 100;
vid.y = 200;
vid.attachCamera(cam);
addChild(vid);
}
}
}
:(我无法实现我的代码:

只需将其作为根类应用,并授予所需的权限即可

包{
导入flash.desktop.NativeApplication;
导入flash.display.Loader;
导入flash.display.MovieClip;
导入flash.display.StageAlign;
导入flash.display.StageScaleMode;
导入flash.events.ErrorEvent;
导入flash.events.Event;
导入flash.events.IOErrorEvent;
导入flash.events.MediaEvent;
导入flash.media.CameraUI;
导入flash.media.MediaPromise;
导入flash.media.MediaType;
导入flash.display.DisplayObject;
导入flash.filesystem.*;
导入flash.events.Event;
导入flash.utils.ByteArray;
导入com.adobe.images.PNGEncoder;
公共类CameraUISaveImage扩展了MovieClip{
私有变量deviceCameraApp:CameraUI=新CameraUI();
私有var-imageLoader:Loader;
private var docsDir:File=File.documentsDirectory;
公共函数camerauisaviemage(){
this.stage.align=StageAlign.TOP_左;
this.stage.scaleMode=StageScaleMode.NO_SCALE;
如果(CameraUI.Isupported){
跟踪(“初始化相机…”);
deviceCameraApp.addEventListener(MediaEvent.COMPLETE,ImageCapture);
deviceCameraApp.addEventListener(Event.CANCEL,CaptureAccessed);
deviceCameraApp.addEventListener(ErrorEvent.ERROR,cameraError);
deviceCameraApp.launch(MediaType.IMAGE);
}否则{
跟踪(“不支持摄像头接口”);
}
}
私有函数ImageCapture(事件:MediaEvent):无效{
跟踪(“捕获的媒体…”);
var-imagePromise:MediaPromise=event.data;
if(imagePromise.isAsync){
跟踪(“异步媒体承诺”);
imageLoader=新加载器();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,asyncImageLoaded);
imageLoader.addEventListener(IOErrorEvent.IO_ERROR,cameraError);
加载文件承诺(imagePromise);
}否则{
跟踪(“同步媒体承诺”);
加载文件承诺(imagePromise);
保存媒体(图像加载器);
}
}
私有函数捕获已取消(事件:事件):无效{
跟踪(“媒体捕获已取消”);
NativeApplication.NativeApplication.exit();
}
私有函数asyncImageLoaded(事件:事件):void{
跟踪(“加载到内存中的媒体”);
保存媒体(图像加载器);
}
专用函数saveMedia(加载程序:加载程序):无效{
试一试{
docsDir=File.applicationDirectory
browseForSave文件(“另存为”);
docsDir.addEventListener(Event.SELECT,saveData);
}捕获(错误:错误){
跟踪(“失败:”,错误消息);
}
}
函数saveData(事件:event):void{
var newFile:File=event.target作为文件;
if(!newFile.exists)//如果覆盖正常,则删除此“if”。
{
var-stream:FileStream=new FileStream();
打开(newFile,FileMode.WRITE);
stream.writeBytes(imageLoader.loaderInfo.bytes);
stream.close();
}else跟踪('所选路径已存在');
}
专用函数cameraError(错误:ErrorEvent):无效{
跟踪(“错误:+Error.text”);
NativeApplication.NativeApplication.exit();
}
}
}