iPhone - 镜像从前面的相机拍摄的照片 [英] iPhone - Mirroring back a picture taken from the front camera
问题描述
当使用iPhone 4的前置摄像头拍摄照片时,拍摄的照片与您在iPhone屏幕上看到的照片相比较。如何恢复UIImage(而不是UIImageView)的屏幕视图,并能够像这样保存?
我试过:
UIImage * transformedImage = [UIImage imageWithCGImage:pickedImage.CGImage scale:1.0 orientation:UIImageOrientationLeftMirrored];
UIImageWriteToSavedPhotosAlbum(convertedImage,self,@selector(photoSaved:didFinishSavingWithError:contextInfo :),nil);
然后将其放在屏幕上。
所以...如何恢复屏幕上的屏幕上视图? 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();
但这只是一个黑色的图像。
解决方案 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(convertedImage,self,@selector(photoSaved:didFinishSavingWithError:contextInfo :),nil);
这是写出来的内存,没有编译器的帮助,请不要复制和粘贴。 ..
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 ?
I tried :
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.
So... How may I restore the "on screen" view of the UIImage (not the UIImageView), and be able to save it like this ?
I also tried this way :
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屋!