在我的AIR应用程序中,用户可以拍摄照片(来自CameraRoll或CameraUI)并将其保存到服务器。
有没有办法自动调整图像大小(800x600)以获得更轻的文件?
这是我的代码:
var now:Date = new Date();
var saveDirectory:String= "MyApp/PhotoUploads";
var fileName:String = "MyPhoto" + now.fullYear + now.month + now.day + now.hours + now.minutes + now.seconds + ".jpg";
var photoFile:File=File.documentsDirectory.resolvePath(saveDirectory+"/"+ fileName);
function imageSelected( event:MediaEvent ):void{
var mp:MediaPromise = event.data;
dataSource = mp.open();
readMediaData();
}
function readMediaData():void{
var imageBytes:ByteArray = new ByteArray();
dataSource.readBytes( imageBytes );
var stream:FileStream = new FileStream();
stream.addEventListener( Event.CLOSE,photoFileSaved);
stream.openAsync( photoFile,FileMode.WRITE);
stream.writeBytes( imageBytes );
stream.close();
}
function photoFileSaved(evt:Event):void{
photoUpload();
}
function photoUpload():void{
photoFile.upload( req );
photoFile.addEventListener( ProgressEvent.PROGRESS, progress_func );
photoFile.addEventListener( IOErrorEvent.IO_ERROR, ioErrorMedia );
photoFile.addEventListener( Event.COMPLETE, complete_func );
}
显然我无法做到:
mp.width = 200;
mp.height= 200;
那我怎么能这样做?
答案 0 :(得分:1)
false