Rotate CGImage taken from video frame

和自甴很熟 提交于 2019-11-28 19:32:31
John Carter

Depends on whether you are using the front camera or the back camera

int frontCameraImageOrientation = UIImageOrientationLeftMirrored;
int backCameraImageOrientation = UIImageOrientationRight;

UIImage *image = [[UIImage alloc] initWithCGImage:newImage scale:(CGFloat)1.0 orientation:frontCameraImageOrientation];

You can change videoOrientation, this way you get a correct image

connection.videoOrientation = AVCaptureVideoOrientationPortrait

Because by default Video orientation is not portrait.

Just rotate the context

Simply rotate the context in radians. This call would rotate the context 90 degrees.

CGFloat degrees = 90.f;
CGFloat radians = degrees * (M_PI / 180.f);
CGContextRotateCTM(context, radians);

You can easily set this method to take the desired orientation and rotate accordingly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!