protected function button1_clickHandler(event:MouseEvent):void
{
_fr = new FileReference();
_fr.addEventListener(Event.SELECT, onSelected);
var filter:FileFilter = new FileFilter("Images: (*.jpg,*.jpeg,*.gif,*.png)","*.jpg;*.jpeg;*.gif;*.png");
_fr.browse([filter]);
}
private function onSelected(evt:Event):void
{
trace( evt.type );
_fr.removeEventListener(Event.SELECT, onSelected);
_fr.addEventListener(Event.COMPLETE, onCompleted);
_fr.load();
}
private function onCompleted(evt:Event):void
{
_fr.removeEventListener(Event.COMPLETE, onCompleted);
var ld:Loader = new Loader();
ld.contentLoaderInfo.addEventListener(Event.COMPLETE, loadBytesHandler);
ld.loadBytes( _fr.data );
}
private function loadBytesHandler(evt:Event):void
{
var loaderInfo:LoaderInfo = (evt.target as LoaderInfo);
loaderInfo.removeEventListener(Event.COMPLETE, loadBytesHandler);
showImage(loaderInfo.content);
}
private function btnSave_clickHandler(evt:MouseEvent):void
{
var imageData:BitmapData = new BitmapData(_img.width/2, _img.height/2);
var shiftOrigin:Matrix = new Matrix();
shiftOrigin.translate(-_img.x, -_img.y);
imageData.draw(_img, shiftOrigin);
var encodedImage:ByteArray;
// if (_cropStateView.outputFormat == CropStateView.JPEG) {
var jpgEncoder:JPGEncoder = new JPGEncoder(85);
encodedImage = jpgEncoder.encode( imageData );
// }
// else {
// encodedImage = PNGEncoder.encode(imageData);
// }
var fileNameRegExp:RegExp = /^(?P<fileName>.*)\..*$/;
var outputFileName:String = fileNameRegExp.exec(_fr.name).fileName + "_export";
// if (_cropStateView.outputFormat == CropStateView.JPEG) {
outputFileName += ".jpg";
// } else {
// outputFileName += ".png";
// }