我正在嘗試使用fullScreenImage
方法從ALAssetRepresentation
正確旋轉UIImage
。我有幾張測試照片以各種設備方向拍攝;照片在照片應用中正確顯示。對於fullScreenImage
文檔說:如何從ALAssetRepresentation獲取正確旋轉的UIImage?
在iOS 5中,後來,這個方法返回一個完全裁剪,旋轉,調整 圖像完全一樣,用戶會在照片或圖像 選擇器看到的。
要從
CGImage
創建正確地旋轉的UIImage
對象,可以使用imageWithCGImage:scale:orientation:
或initWithCGImage:scale:orientation:
,傳球orientation
和scale
的值。
鑑於文檔,我的代碼看起來是這樣的:
ALAssetRepresentation *rep = [asset defaultRepresentation];
UIImage *img = [UIImage
imageWithCGImage:[rep fullScreenImage]
scale:[rep scale]
orientation:[rep orientation]];
但由此產生的UIImage
的自轉是錯誤的。當我將[rep orientation]
替換爲UIImageOrientationUp
時,對於所有測試照片來說圖像都很好。顯然,我很猶豫要堅持這個「解決方案」,因爲它感覺像一個黑客。我究竟做錯了什麼?
你好,亨德里克,並再次感謝您的答案!然後我會提交一個針對文檔的bug請求,因爲它沒有明確說明第二段只適用於iOS4。 PS:你可能想從你的帖子中刪除簽名,看看[這個元線程](http://meta.stackexchange.com/questions/5029/are-taglines-signatures-disallowed)。 – zoul
作爲[rdar:// 11604456](http://openradar.appspot.com/11604456)提交,並在即將推出的iOS 6發行版的一個月後通過忽略第二個稍有混淆的段落解決。 – zoul
謝謝!我現在正在爲這個問題(和其他相關問題)苦苦掙扎近一個星期。這是iOS5/iOS6真正意義上的第一個答案。你是我的英雄;) –