iPhone - 镜像从前置摄像头拍摄的照片 [英] iPhone - Mirroring back a picture taken from the front camera

查看:21
本文介绍了iPhone - 镜像从前置摄像头拍摄的照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 iPhone 4 的前置摄像头拍照时,所拍摄的照片与您在 iPhone 屏幕上看到的照片相比是镜像的.如何恢复 UIImage(而不是 UIImageView)的屏幕上"视图,并能够像这样保存它?

When using the front camera of the iPhone 4 to take a picture, the taken picture is mirrored compared with what you see on the iPhone screen. How may I restore the "on screen" view of the UIImage (not the UIImageView), and be able to save it like this ?

我试过了:

UIImage* transformedImage = [UIImage imageWithCGImage:pickedImage.CGImage scale:1.0 orientation:UIImageOrientationLeftMirrored];
UIImageWriteToSavedPhotosAlbum (transformedImage, self, @selector(photoSaved:didFinishSavingWithError:contextInfo:), nil);

然后把它放在屏幕上.它与屏幕上看到的几乎相同,但保存的图像失真了.

then putting it on screen. It is nearly the same as seen on screen, but the saved image is distorted.

那么...我怎样才能恢复 UIImage(而不是 UIImageView)的屏幕上"视图,并能够像这样保存它?

我也试过这种方式:

UIImage* pickedImage = [[info objectForKey:UIImagePickerControllerOriginalImage] retain];
UIImage* transformedImage;

CGSize imageSize = pickedImage.size;
UIGraphicsBeginImageContextWithOptions(imageSize, YES, 1.0);
GContextRef ctx = UIGraphicsGetCurrentContext();

CGContextRotateCTM(ctx, 3.14);  // rotate by 180°
CGContextScaleCTM(ctx, 1.0, -1.0); // flip vertical
CGContextDrawImage(ctx, CGRectMake(0.0, 0.0, imageSize.width, imageSize.height), pickedImage.CGImage);
transformedImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

但这只会给出黑色图像.

But that just gives a black image.

推荐答案

最好的方法是将图像绘制到新的上下文中.

The best way is to draw the image into a new context.

CGSize imageSize = pickedImage.size;
UIGraphicsBeginImageContextWithOptions(imageSize, YES, 1.0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, imageSize.width, 0.0);
CGContextScaleCTM(ctx, -1.0, 1.0);
CGContextDrawImage(ctx, pickedImage.CGImage, CGRectMake(0.0, 0.0, imageSize.width, imageSize.height));
UIImage *transformedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum (transformedImage, self, @selector(photoSaved:didFinishSavingWithError:contextInfo:), nil);

这是在没有编译器帮助的情况下从内存中写入的,请不要复制和粘贴...

This was written out of memory and without aid of a compiler, please don't copy and paste...

这篇关于iPhone - 镜像从前置摄像头拍摄的照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆