我使用-writeImageToSavedPhotosAlbum
將圖像發送到照片庫。我遇到的問題是,儘管指定了方向,圖像最終的方向卻是錯誤的。爲什麼-writeImageToSavedPhotosAlbum不正確地定位我的照片?
事實上,似乎是定向AVCaptureVideoOrientationPortrait
末看起來像AVCaptureVideoOrientationPortraitUpsideDown
, 和AVCaptureVideoOrientationLandscapeLeft
結束看起來像AVCaptureVideoOrientationLandscapeRight
,反之亦然的。
爲什麼會有這種情況發生?這裏有一些更多的細節:
我沒有ViewController做我的看法的自動方向更改。
所有圖片顯示[image imageOrientation]
等於AVCaptureVideoOrientationPortrait
,但我跟蹤實際方向並將其單獨傳遞給-writeImageToSavedPhotosAlbum
。
我使用:-writeImageToSavedPhotosAlbum:orientation:completionBlock:
我會很感激,如果有人可以提供一些線索到此。
UPDATE:
儘管我的文檔中讀取,
如果你想保存一個UIImage對象,你可以使用UIImage的方法 CGImage獲得CGImageRef,投圖像的imageOrientation爲 ALAssetOrientation。
我繼續改變了我在傳遞方向:
switch (lastOrientation) {
case UIDeviceOrientationPortrait:
default:
alOrientation = ALAssetOrientationUp;
break;
case UIDeviceOrientationPortraitUpsideDown:
alOrientation = ALAssetOrientationDown;
break;
case UIDeviceOrientationLandscapeLeft:
alOrientation = ALAssetOrientationLeft;
break;
case UIDeviceOrientationLandscapeRight:
alOrientation = ALAssetOrientationRight;
break;
}
[library writeImageToSavedPhotosAlbum:[image CGImage]
orientation:(ALAssetOrientation) alOrientation// [image imageOrientation]
completionBlock:^(NSURL *assetURL, NSError *error) {
NSLog(@"completion block");
}];
現在,所有的圖像得到取向爲它們的左邊緣下來,彷彿他們是景觀權。我仍然沒有對,但至少我有統一導向。
另一個更新:
這個工程。爲什麼,我不知道:
switch (lockedOrientation) {
case UIDeviceOrientationPortrait:
default:
alOrientation = ALAssetOrientationRight; //3 instead ofALAssetOrientationUp;
break;
case UIDeviceOrientationPortraitUpsideDown:
alOrientation = ALAssetOrientationLeft; //2 insted of ALAssetOrientationDown;
break;
case UIDeviceOrientationLandscapeLeft:
alOrientation = ALAssetOrientationUp; //0 instead of ALAssetOrientationLeft;
break;
case UIDeviceOrientationLandscapeRight:
alOrientation = ALAssetOrientationDown; //1 instead of ALAssetOrientationRight;
break;
}
[library writeImageToSavedPhotosAlbum:[image CGImage]
orientation:(ALAssetOrientation) alOrientation// [image imageOrientation]
completionBlock:^(NSURL *assetURL, NSError *error) {
NSLog(@"completion block");
}];
什麼是最後一段代碼中的「lockedOrientation」? – ebi