2011-10-31 18 views
8

Sto utilizzando -writeImageToSavedPhotosAlbum per inviare immagini alla Libreria foto. Il problema che sto avendo è che, nonostante specifichi un orientamento, le immagini finiscono con gli orientamenti sbagliati.Perché -writeImageToSavedPhotosAlbum non orientare correttamente la mia immagine?

Infatti, sembra che quelli che sono orientate AVCaptureVideoOrientationPortrait fine assomigliare AVCaptureVideoOrientationPortraitUpsideDown, e AVCaptureVideoOrientationLandscapeLeft fine assomigliare AVCaptureVideoOrientationLandscapeRight e viceversa.

C'è qualche motivo per cui questo sta accadendo? Ecco alcuni dettagli:

Non ho ViewController che esegue il cambio di orientamento automatico per la mia vista.
Tutte le immagini mostrano [image imageOrientation] uguale a AVCaptureVideoOrientationPortrait, ma tengo traccia dell'orientamento effettivo e lo inoltro a -writeImageToSavedPhotosAlbum in modo indipendente.

sto usando: -writeImageToSavedPhotosAlbum:orientation:completionBlock:

lo apprezzerei se qualcuno potesse fare luce su questo.

UPDATE:

Nonostante quello che ho letto nella documentazione,

Se si desidera salvare un oggetto UIImage, è possibile utilizzare il metodo UIImage CGImage per ottenere un CGImageRef, e lanciare l'immagine del imageOrientation a ALAssetOrientation.

sono andato avanti e ha cambiato l'orientamento passo in:

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

Ora, tutte le immagini orientarsi con il loro bordo sinistro verso il basso, come se fossero paesaggio-destra. Non ho ancora ragione, ma almeno li ho orientati in modo uniforme.

Un altro AGGIORNAMENTO:

Questo funziona. Perché, non lo so:

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

Che cosa è "lockedOrientation" nell'ultimo snippet di codice? – ebi

risposta

1

Questo problema è dovuto al fatto che UIDeviceOrientation e ALAssetOrientation hanno valori enumerati diversi. Verificare la definizione sia per enum qui di seguito:

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 
}; 

Così, per UIDeviceOrientationUnknown stessa sarà UIDeviceOrientationUnknown (int value 0); per UIDeviceOrientationPortrait sarà uguale ALAssetOrientationDown (valore int 1) e così via

0

Sei sicuro che l'immagine non è il risparmio con l'orientamento corretto e non sei solo rispettando l'orientamento quando si visualizza esso?

È possibile caricare la risorsa nel blocco di completamento e controllare l'orientamento lì per essere sicuri.

Problemi correlati