要捕获图像,您也应该设置方向。当您将图像保存到磁盘时,您应该使用
writeImageToSavedPhotosAlbum:orientation:completionBlock:
功能并在那里设置正确的“方向”参数。
用法:https ://developer.apple.com/library/ios/documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/index.html#//apple_ref/occ/instm/ALAssetsLibrary/writeImageToSavedPhotosAlbum:orientation:completionBlock :
目标 C 示例:
// Flash set to Auto for Still Capture
[CameraViewController setFlashMode:AVCaptureFlashModeAuto
forDevice:[[self videoDeviceInput] device]];
// Capture a still image.
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo]
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (imageDataSampleBuffer) {
self.imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
[[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:image.CGImage
orientation:(ALAssetOrientation)[image imageOrientation]
completionBlock:^(NSURL *assetURL, NSError *error) {
if(error == nil) {
NSLog(@"PHOTO SAVED - assetURL: %@", assetURL);
} else {
NSLog(@"ERROR : %@",error);
}
}];