2012-03-22 55 views
3

我在iPhone上正確定位圖像時出現問題。我正在使用AssetLibrary類訪問圖像。使用ALAssetOrientation和UIImageOrientation確定正確方向的問題

所有我想要做的就是正確定位顯示的圖像,不幸的是,對於某些以縱向模式拍攝的圖像,它們的方向不合理。

在那種年代由框架調用該塊,我正在爲在,而這是面向「上」採取的iPhone攝像頭的圖片下面的調用:

 ALAssetRepresentation *representation = [myasset defaultRepresentation]; 
     ALAssetOrientation  orient   = [representation orientation]; 
     ALAssetOrientation  alorient = [[myasset valueForProperty:@"ALAssetOrientation"] intValue]; 
     UIImage     *timg   = [[UIImage alloc] initWithCGImage:[representation fullScreenImage]]; 
     UIImageOrientation  imgorient  = [timg imageOrientation]; 

THe variable orient = ALAssetOrientationRight. 
The variable alorient = ALAssetOrientationUp. 
The variable imgorient = UIImageOrientationUp 

我用的是定向旋轉圖像以使其看起來「向上」。不幸的是,如果我有橫向模式拍攝的圖像,則相同的代碼不起作用,因爲方向不正確。

我試過使用scale來實例化timg:orientation:使用Orient對過程參數進行過載,它所做的只是初始化設置方向但不正確旋轉圖像的圖像。

這似乎不確定性,這些電話是怎麼來返回不同的結果:

ALAssetOrientation  orient = [representation orientation]; 
ALAssetOrientation  alorient = [[myasset valueForProperty:@"ALAssetOrientation"] intValue]; 

您的幫助將不勝感激。

感謝, 威爾

+0

說真的,沒有人對此發表評論?!!? – willmapp 2012-03-27 00:13:00

回答

0

的問題是,你使用了錯誤的屬性名稱。

在您的代碼:

[[myasset valueForProperty:@"ALAssetOrientation"] intValue]; 

應該是:

[[myasset valueForProperty:@"ALAssetPropertyOrientation"] intValue]; 

按照documentation-[ALAsset valueForProperty:]

If property is not a valid key, returns ALErrorInvalidProperty. 

您的代碼嘗試將ALErrorInvalidProperty轉換爲int,結果爲0。巧合ALAssetOrientationUp的值爲0這就是爲什麼您的alorient變量總是會評估爲ALAssetOrientationUp