2012-05-15 85 views
1

請幫助,我已經成功地通過iphone的相機訪問和捕捉照片。但問題是當我通過「loadFilePromise」加載它時,照片旋轉方向錯誤。Flash CS5.5:使用iPhone上的CameraUI捕捉照片時旋轉照片

import flash.media.CameraUI; 
import flash.media.MediaType; 
import flash.media.MediaPromise; 
import flash.events.MediaEvent; 
import flash.events.Event; 
import flash.events.MouseEvent; 
import flash.display.Loader; 
import flash.display.Bitmap; 
import flash.media.CameraRoll; 
import flash.display.StageOrientation; 
import flash.events.StageOrientationEvent; 
import flash.media.Camera; 
import flash.media.Video; 

var currentOrientation:String = ""; 

var cam:CameraUI = new CameraUI(); 
cam.addEventListener(MediaEvent.COMPLETE, captured); 
cam.addEventListener(Event.CANCEL, cancelled); 

var loader:Loader = new Loader(); 
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, photoLoaded); 
addChild(loader); 

captureBtn.addEventListener(MouseEvent.MOUSE_UP, pressed); 

function pressed(e:MouseEvent){ 
    if(CameraUI.isSupported){ 
     cam.launch(MediaType.IMAGE); 
    } 
} 

function captured(e:MediaEvent){ 
    var mediaPromise:MediaPromise = e.data; 
    if(mediaPromise != null) 
    { 
     output.text = "Photo captured."; 
     loader.loadFilePromise(mediaPromise); 
    } 
} 

function cancelled(e:Event):void { 
    output.text = "Cancelled."; 
} 

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING,orientationChanging); 
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, orientationChanged); 

function orientationChanging(e:StageOrientationEvent){ 
    currentOrientation = e.afterOrientation; 
    trace(currentOrientation); 
    switch(currentOrientation) 
    { 
     case StageOrientation.DEFAULT : 
      currentOrientation = "DEFAULT"; 
      //set rotation value here 
      stage.rotation = 0; 
      break; 

     case StageOrientation.ROTATED_RIGHT : 
      currentOrientation = "ROTATED_RIGHT"; 
      //set rotation value here 
      stage.rotation = -90; 
      break; 

     case StageOrientation.ROTATED_LEFT : 
      currentOrientation = "ROTATED_LEFT"; 
      //set rotation value here 
      stage.rotation = 90; 
      break; 

     case StageOrientation.UPSIDE_DOWN : 
      currentOrientation = "UPSIDE_DOWN"; 
      //set rotation value here 
      stage.rotation = 180; 
      break; 
    } 
} 

function orientationChanged(e:StageOrientationEvent){ 

} 

function photoLoaded(e:Event){ 
    var img:Bitmap = e.currentTarget.content as Bitmap; 
    img.smoothing = true; 
    img.width = 350 
    img.scaleY = img.scaleX; 

    /* TRY THIS TO FIX BUT IT DIDN'T WORK: 
     switch(currentOrientation){ 

     case "rotatedLeft": 
      img.rotation = 90; 
     break; 

     case "rotatedRight": 
      img.rotation = 90; 
     break; 

     case "upsideDown": 

     break; 

    }*/ 

    /* THESE LINE ARE JUST USED TO SAVE PHOTO IN CAMERA ROLL: 
     if(CameraRoll.supportsAddBitmapData) 
    { 
     cameraRoll.addBitmapData(img.bitmapData); 
    }*/ 
} 

function camRollSaved(e:Event){ 
    output.text = "Your photo is saved to a camera roll." 
} 

我已經在發佈設置中未選中「自動定位」,試圖更正StageOrientation,但它仍然無法工作。

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING,orientationChanging); 
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, orientationChanged); 

這是唯一正確的,當我將iphone旋轉到lanscape(相機的位置在TOP-RIGHT),然後拍照。

有沒有人有同樣的問題或知道如何解決它?

非常感謝,

+0

這是一個已知的錯誤。請到https://bugbase.adobe.com/index.cfm?event=bug&id=4070057投票,也許Adobe會修復它。 –

回答

1

這解決了這個問題,我在Android上: http://blog.flexnroses.com/?p=95

我認爲這是與iOS的庫出了問題,所以它可能不是解決你的問題,但也許你可以從這裏獲得你需要的靈感。祝你好運!