如何从UIImagePickerController镜像UIImage图片 [英] How do I mirror a UIImage picture from UIImagePickerController

查看:88
本文介绍了如何从UIImagePickerController镜像UIImage图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定是否有任何方法可以镜像图像.例如,拍摄某人的脸的照片,然后将其切成两半,并在两边都镜像的情况下显示出他们的脸.CGAffineTransform函数中似乎没有这样的技巧.图形专家请帮助!!!

I'm trying to figure out if there is any way to mirror an image. For example, take a picture of someone's face and then cut it in half and show what their face looks like with each side mirrored. There doesn't seem to be any tricks like this in CGAffineTransform functions. Graphics experts please help!!!

推荐答案

此处的基本技巧"是使用绕X轴或Y轴的缩放比例为-1的变换.例如,您可以使用它来创建围绕水平轴翻转"变换:

The basic "trick" here is to use a scaling transform about the X or Y axis with a factor of -1. For example, you could use this to create a "flip about the horizontal axis" transform:

CGAffineTransform transform = CGAffineTransformScale(transform, -1, 1);

然后,您可以在 UIImageView 上设置 transform 属性,以翻转分配的图像,或将其与另一种转换连接起来以产生更复杂的效果.为了获得您所描述的确切效果,您可能需要编写一些自定义绘制代码,以将原始图像绘制到上下文中,然后将翻转的一半覆盖在其顶部.在Core Graphics中,这相对简单.

Then you can set the transform property on a UIImageView to flip the assigned image, or concatenate it with another transform to do more sophisticated effects. To get the exact effect you described, you may need to write some custom drawing code to draw your original image into a context, then overlay the flipped half on top of it. This is relatively straightforward in Core Graphics.

这篇关于如何从UIImagePickerController镜像UIImage图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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