Tengo un problema extraño con captureStillImageAsynchronouslyFromConnection. Si guardo la imagen usando jpegStillImageNSDataRepresentation mientras el video está en espejo, la imagen en el rollo de la cámara gira 90 grados en el sentido de las agujas del reloj. Sin embargo, si no se refleja, la orientación es correcta. Voy a publicar el código, ¿alguien más tiene este problema/conozco una solución?AVCaptureMovieFileOutput provoca una orientación incorrecta al guardar fotos en Camera Roll
Actualización: Solo realicé algunas pruebas, las alturas y el ancho (640x480) están bien y reflejan la orientación del dispositivo. Cuando tomo una foto en vertical, informa UIImageOrientationLeft y cuando se refleja, UIImageOrientationLeftMirrored.
Actualización 2: Cuando veo la foto guardada en el carrete, la vista previa de la imagen tiene la orientación correcta, al igual que la imagen cuando desliza entre fotos, pero cuando la foto está completamente cargada, gira 90 grados . ¿Podría ser un problema de rollo de cámara? (Estoy en 4.3.3)
- (void) captureImageAndSaveToCameraRoll
{
AVCaptureConnection *stillImageConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];
if ([stillImageConnection isVideoOrientationSupported])
[stillImageConnection setVideoOrientation:[self orientation]];
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:stillImageConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
ALAssetsLibraryWriteImageCompletionBlock completionBlock = ^(NSURL *assetURL, NSError *error) {
if (error) {
if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)]) {
[[self delegate] captureManager:self didFailWithError:error];
}
}
};
if (imageDataSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[library writeImageToSavedPhotosAlbum:[image CGImage]
orientation:(ALAssetOrientation)[image imageOrientation]
completionBlock:completionBlock];
[image release];
[library release];
}
else
completionBlock(nil, error);
if ([[self delegate] respondsToSelector:@selector(captureManagerStillImageCaptured:)]) {
[[self delegate] captureManagerStillImageCaptured:self];
}
}];
}
para depurar esto, podría ser útil si genera image.size y imageOrientation en ambos modos, ¿qué valores obtiene? – mackross
Solo realicé algunas pruebas, las alturas y el ancho (640x480) están bien y reflejan la orientación del dispositivo. Cuando tomo una foto en vertical, informa UIImageOrientationLeft y cuando se refleja, UIImageOrientationLeftMirrored. –