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