【发布时间】:2011-06-15 00:12:06
【问题描述】:
我对 captureStillImageAsynchronouslyFromConnection 有一个奇怪的问题。如果我在镜像视频时使用 jpegStillImageNSDataRepresentation 保存图像,则相机胶卷中的图像会顺时针旋转 90 度。但是,如果没有镜像,则方向很好。 我会发布代码,其他人有这个问题/知道解决方法吗?
更新:刚刚进行了一些测试,高度和宽度 (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 可能会有所帮助,你会得到什么值?
-
刚刚进行了一些测试,高度和宽度(640x480)都很好,反映了设备的方向。当我在纵向拍照时,它会报告 UIImageOrientationLeft,当镜像时,它会报告 UIImageOrientationLeftMirrored。
标签: iphone ios avfoundation avcapturesession avcam