2013-03-04 53 views
0

Im使用Flash Builder 4.5和AS3從實時JSON數據源動態加載圖像。它的加載和工作正常,並響應我的輕掃手勢(左滑動去回去,右刷卡前進到下一個圖像)...如何檢測圖像方向(人像與風景),然後再加載相應的旋轉階段?

我想添加一些動作來檢測其圖片的方向成功加載那麼如果其垂直方向的照片,把舞臺90度(並設置一些類型的標誌來記住其在「旋轉狀態」。

我怎樣才能做到這一點?

if (myPic && myPic.width > myPic.height) 
{ 
    // this picture is horizontal, so leave stage in normal landscape aspect ratio 
} else { 
    // something here to take the stage and rotate it 90 degrees 
} 

回答

2

您可以使用width:height比例來確定圖片的形狀是縱向還是橫向,我不確定您是否想要旋轉舞臺,而是圖像本身。

這裏是我已經寫了,可以幫助一個類:

public class PhotoHolder extends Sprite 
{ 

    public static const Landscape:int = 0; 
    public static const Portrait:int = 1; 


    private var _bitmap:Bitmap; 
    private var _orientation:int = 0; 


    public function PhotoHolder(bitmap:Bitmap) 
    { 
     _bitmap = bitmap; 
     _bitmap.x = -(_bitmap.width/2); 
     _bitmap.y = -(_bitmap.height/2); 

     if(bitmap.width >= bitmap.height) _orientation = Landscape; 
     else 
     { 
      rotation = 90; 
      _orientation = Portrait; 
     } 

     addChild(_bitmap); 
    } 


    public function get orientation():int 
    { 
     return _orientation; 
    } 

} 

這將管理的轉動你,你就能夠確定,如果圖像原本是通過LandscapePortrait方向.orientation