2011-10-31 14 views
8

Estoy usando -writeImageToSavedPhotosAlbum para enviar imágenes a la Biblioteca de fotos. El problema que tengo es que a pesar de especificar una orientación, las imágenes terminan con las orientaciones incorrectas.¿Por qué -writeImageToSavedPhotosAlbum orienta mi imagen incorrectamente?

De hecho, parece que los que están orientados AVCaptureVideoOrientationPortrait terminar pareciéndose a AVCaptureVideoOrientationPortraitUpsideDown, y AVCaptureVideoOrientationLandscapeLeft terminar pareciéndose a AVCaptureVideoOrientationLandscapeRight y viceversa.

¿Hay alguna razón para que esto suceda? Aquí hay algunos detalles más:

No tengo ViewController haciendo el cambio de orientación automática para mi vista.
Todas las imágenes muestran [image imageOrientation] igual a AVCaptureVideoOrientationPortrait, pero hago un seguimiento de la orientación real y la paso a -writeImageToSavedPhotosAlbum de forma independiente.

que estoy usando: -writeImageToSavedPhotosAlbum:orientation:completionBlock:

lo agradecería si alguien puede arrojar algo de luz sobre esto.

ACTUALIZACIÓN:

A pesar de lo que he leído en la documentación,

Si desea guardar un objeto UIImage, puede utilizar el método UIImage CGImage para obtener una CGImageRef, y echó la imagen de imageOrientation a ALAssetOrientation.

que siguió adelante y cambió la orientación que pase en:

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

Ahora, todas las imágenes a orientarse con su borde izquierdo hacia abajo, como si fueran paisaje-derecha. Todavía no lo tengo bien, pero al menos los tengo uniformemente orientados.

Otra actualización:

Esto funciona. ¿Por qué, no lo sé:

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

¿Qué es "lockedOrientation" en el último fragmento de código? – ebi

Respuesta

1

Tiene este problema porque UIDeviceOrientation y ALAssetOrientation tienen valores de enum diferentes. Compruebe definición para ambos enumeración continuación:

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

Así que para UIDeviceOrientationUnknown misma será UIDeviceOrientationUnknown (int valor 0); para UIDeviceOrientationPortrait será igual a ALAssetOrientationDown (int valor 1) y así sucesivamente

0

¿Seguro de que la imagen no es el ahorro con la orientación correcta y simplemente no estamos respetando la orientación al mostrar que?

Puede cargar el activo en el bloque de finalización y verificar la orientación allí para asegurarse.

Cuestiones relacionadas