2011-10-31 25 views
8

Fotoğraf Kitaplığı'na görüntüleri göndermek için -writeImageToSavedPhotosAlbum kullanıyorum. Benim sahip olduğum problem, bir yönelimi belirtmesine rağmen, görüntülerin yanlış yönelimler ile sonuçlanmasıdır. AslındaNeden -writeImageToSavedPhotosAlbum resmimi yanlış yönlendiriyor?

Öyle görülüyor ki, AVCaptureVideoOrientationPortraitUpsideDown, ve AVCaptureVideoOrientationLandscapeLeft sonuna kadar AVCaptureVideoOrientationLandscapeRight ve tersi gibi bakıyor gibi bakıyor AVCaptureVideoOrientationPortrait ucunu yukarı dönük olanlar.

Bunun olmasının bir nedeni var mı? Bazı ek ayrıntılar şunlardır:

hiçbir ViewController benim görünümü için otomatik yön değişikliğini yapıyor sahiptir.
Tüm resimler AVCaptureVideoOrientationPortrait eşit [image imageOrientation] gösterir, ancak ben asıl yönelimi izlemek ve bağımsız -writeImageToSavedPhotosAlbum geçmektedir.

kullanıyorum: Birisi bu bir kaç ışık kaynağı eğer -writeImageToSavedPhotosAlbum:orientation:completionBlock:

memnun olurum.

GÜNCELLEME: Bir UIImage nesnesini kaydetmek isterseniz

Ben belgelerinde okuduklarım rağmen

,

, resim en bir CGImageRef almak için UIImage yöntemini CGImage kullanın ve yayın yapabilirsiniz image ALAssetOrientation.

devam ettim ve ben geçmek yönünü değiştirdi: bunlar manzara-haklısın sanki Şimdi

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"); 
         }]; 

, bütün görüntüler, onların sol kenarı aşağı dönük olsun. Hala doğru değilim, ama en azından onları düzgün bir şekilde yönlendirdim.

Başka bir güncelleştirme:

Bu çalışır. Neden, bilmiyorum:

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"); 
          }]; 
+0

Son kod snippet'inde "lockedOrientation" nedir? – ebi

cevap

1

bu sorunla var. Aşağıda hem enum için tanımını kontrol edin:

typedef NS_ENUM(NSInteger, UIDeviceOrientation) { 
    UIDeviceOrientationUnknown, 
    UIDeviceOrientationPortrait,   // Device oriented vertically, home button on the bottom 
    UIDeviceOrientationPortraitUpsideDown, // Device oriented vertically, home button on the top 
    UIDeviceOrientationLandscapeLeft,  // Device oriented horizontally, home button on the right 
    UIDeviceOrientationLandscapeRight,  // Device oriented horizontally, home button on the left 
    UIDeviceOrientationFaceUp,    // Device oriented flat, face up 
    UIDeviceOrientationFaceDown    // Device oriented flat, face down 
}; 

typedef NS_ENUM(NSInteger, ALAssetOrientation) { 
    ALAssetOrientationUp,   // default orientation 
    ALAssetOrientationDown,   // 180 deg rotation 
    ALAssetOrientationLeft,   // 90 deg CCW 
    ALAssetOrientationRight,   // 90 deg CW 
    ALAssetOrientationUpMirrored, // as above but image mirrored along other axis. horizontal flip 
    ALAssetOrientationDownMirrored, // horizontal flip 
    ALAssetOrientationLeftMirrored, // vertical flip 
    ALAssetOrientationRightMirrored, // vertical flip 
}; 

Yani UIDeviceOrientationUnknown UIDeviceOrientationUnknown olacak aynı (int değeri 0) için; UIDeviceOrientationPortrait için eşit ALAssetOrientationDown (int değeri 1) ve benzeri

0

Görüntünün doğru yönlendirmeyle kaydedilmediğinden ve görüntülediğinizde yalnızca yönlendirmeye uymadığınızdan emin misiniz?

Sen tamamlama bloğunda varlığı yüklemek ve emin olmak için orada yönünü kontrol edebilir. UIDeviceOrientation ve ALAssetOrientation farklı enum değerleri çünkü

İlgili konular