我对 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];
}
}];
}