CaptureStillImageAsynchronouslyFromConnection存在一个奇怪的问题。如果在镜像视频时使用jpegStillImageNSDataRepresentation保存图像,则相机胶卷中的图像将顺时针旋转90度。但是,如果它没有镜像,方向就很好。 我会发布代码,任何人都有这个问题/知道修复?AVCaptureMovieFileOutput将照片保存到相机胶卷时导致错误的方向
更新:只是跑了一些测试,高度和宽度(640x480)都很好,反映了设备的方向。当我以纵向拍摄照片时,它会报告UIImageOrientationLeft和镜像时的UIImageOrientationLeftMirrored。
更新2:当我在相机胶卷中查看保存的照片时,图像的预览具有正确的方向,当您在照片之间滑动时的图像也是如此,但是当照片完全加载时,它会旋转90度。这可能是相机胶卷问题吗? (我在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];
}
}];
}
调试这可能会有所帮助,如果你在这两种模式下输出image.size和imageOrientation,你会得到什么值? – mackross 2011-06-15 01:58:50
只是跑了一些测试,高度和宽度(640x480)都很好,反映了设备的方向。当我以纵向拍摄照片时,它会报告UIImageOrientationLeft和镜像时的UIImageOrientationLeftMirrored。 – 2011-06-15 02:13:21