W D*_*son 5 iphone avfoundation ios avcapturesession avcam
我对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];
}
}];
}
Run Code Online (Sandbox Code Playgroud)
我想知道您新创建的图像是否真的具有您在这里假设的方向设置:
[library writeImageToSavedPhotosAlbum:[image CGImage] orientation: (ALAssetOrientation) [image imageOrientation] completionBlock:completionBlock];
Run Code Online (Sandbox Code Playgroud)
[image imageOrientation]特别是似乎可能是问题的根源,尤其是需要演员阵容......
你说你在某处看到图像方向,是在使用[image imageOrientation]以下命令创建之后不久的吗?
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation: imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
Run Code Online (Sandbox Code Playgroud)
我想知道您是否假设该元数据是imageData从AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:实际上仅包含图像像素数据本身的情况返回的?