iPhone - Mirroring back a picture taken from the front camera

前端 未结 8 2066
半阙折子戏
半阙折子戏 2020-12-24 04:06

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 scre

8条回答
  •  孤城傲影
    2020-12-24 04:27

    I know this question was already answered, but the answer above didn't work for me so in case there are others...

    UIImage *theImage = [info objectForKey:UIImagePickerControllerOriginalImage];
        if (picker.cameraDevice == UIImagePickerControllerCameraDeviceFront) {
            CGSize imageSize = theImage.size;
            UIGraphicsBeginImageContextWithOptions(imageSize, YES, 1.0);
            CGContextRef ctx = UIGraphicsGetCurrentContext();
            CGContextRotateCTM(ctx, M_PI/2);
            CGContextTranslateCTM(ctx, 0, -imageSize.width);
            CGContextScaleCTM(ctx, imageSize.height/imageSize.width, imageSize.width/imageSize.height);
            CGContextDrawImage(ctx, CGRectMake(0.0, 0.0, imageSize.width, imageSize.height), theImage.CGImage);
            UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
        }
    

    and newImage is your new image with the up orientation

提交回复
热议问题