GPUImage カメラを使用して、カメラを次のようにセットアップしました
- (void)setupSessionWithImageView:(GPUImageView *)captureView
{
GPUImageStillCamera *stillCamera = [[GPUImageStillCamera alloc] init];
GPUImageGammaFilter *colorFilter = [[GPUImageGammaFilter alloc] init];
[stillCamera addTarget:colorFilter];
[colorFilter addTarget:captureView];
self.colorFilter = colorFilter;
self.stillCamera = stillCamera;
self.captureView = captureView;
[stillCamera startCameraCapture];
}
viewWillTransitionToSize:
View Controller で が呼び出されたときに Apple の iPad カメラを模倣するためoutputImageOrientation
に、静止カメラの を更新します。これにより、ビデオ プレビューが回転し、iPad の向きが変わっても正しい向きが維持されます。
- (void)setOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationUnknown) { // default to portrait if we don't know
interfaceOrientation = UIInterfaceOrientationPortrait;
}
self.stillCamera.outputImageOrientation = interfaceOrientation;
}
私の問題は、iOS 9 を使用してこの設定で写真をキャプチャすると、すべての横長の画像が縦長の画像であるかのようにサイズを報告します (したがって、短辺は幅の測定値であり、長さは高さの測定値です)。ただし、向きは正しく報告されます。What's New in iOS 9 Guideは、これに影響を与える可能性があると思われる AVFoundation への変更を示していません。を PortraitのままにしておくとoutputImageOrientation
、これは解決しますが、ビューを回転させて iPad で Apple のネイティブ カメラ機能を模倣することはできません。
- (void)captureImage
{
GPUImageStillCamera *stillCamera = self.stillCamera;
[stillCamera capturePhotoAsImageProcessedUpToFilter:self.colorFilter withCompletionHandler:^(UIImage *processedImage, NSError *error) {
NSLog(@"image orientation %ld", (long)processedImage.imageOrientation);
NSLog(@"image size %f width x %f height", processedImage.size.width, processedImage.size.height);
}];
}
GPUImage の実装や、カメラの向きの変更の処理方法に問題はありますか? サンプル プロジェクト全体は、私の git ページにあります。iOS 8 以前では、画像がサイズを報告する前に、向きのプロパティが正確に反映されていました。