iPhoneのフロントカメラを使ったアプリを作っています。このカメラで撮影すると、iPhoneで横に振られます。ミラーリングして保存し、iPhone画面に表示されたとおりに表示したいと思います。
私はたくさんのドキュメントとネット上のたくさんのアドバイスを読みました、そして私はまだ非常に混乱しています。
私の調査と多くの試みの結果、保存と表示の両方に役立つソリューションが見つかりました。
- (UIImage *) flipImageLeftRight:(UIImage *)originalImage {
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:originalImage];
UIGraphicsBeginImageContext(tempImageView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGAffineTransform flipVertical = CGAffineTransformMake(
1, 0,
0, -1,
0, tempImageView.frame.size.height
);
CGContextConcatCTM(context, flipVertical);
[tempImageView.layer renderInContext:context];
UIImage *flipedImage = UIGraphicsGetImageFromCurrentImageContext();
flipedImage = [UIImage imageWithCGImage:flipedImage.CGImage scale:1.0 orientation:UIImageOrientationDown];
UIGraphicsEndImageContext();
[tempImageView release];
return flipedImage;
}
しかし、それは盲目的な使用であり、私は何が行われているのか理解していません。
2つのimageWithCGImageを使用してミラーリングし、180°回転させようとしましたが、不思議な理由で機能しません。
だから私の質問は:私が機能する最適化されたメソッドを書くのを手伝ってくれませんか、そしてそれがどのように機能するかを理解することができます。マトリックスは私にとってブラックホールです...