裁剪UIImage以适合帧图像 [英] Crop UIImage to fit a frame image
问题描述
我需要使用设备相机裁剪 UIImage
,以便它适合另一个 UIImage
,代表框架
(带圆角边框等)。检查下图:
I need to crop a UIImage
, taken with the device camera, so that it fits inside another UIImage
, which represents a frame
(with rounded borders and so on). Check the image below:
使用Aspect Fill
Using Aspect Fill
使用Aspect Fit
Using Aspect Fit
因此,我需要的是删除超出帧边界的图像。
我尝试使用 UIBezierPath
, CGImageRef
以及我用Google搜索的其他方法,但我找不到解决方法为此。
So, what I need is to remove the image excess that is out of the frame bounds.
I tried using UIBezierPath
, CGImageRef
and other methods that I Googled but I'm not finding a solution for this.
推荐答案
在Interface Builder中,使用以下配置:
In Interface Builder, use the following configuration:
有两个重要设置,即:
-
模式:Aspect Fill
剪辑子视图
它也可以通过编程方式完成:
It can also be done programmatically:
[imageView setContentMode:UIViewContentModeScaleAspectFill];
[imageView setClipsToBounds:YES];
这将正确填充图像的视图,保持其宽高比并隐藏不适合的内容。
This will correctly fill the view with the image, keep its aspect ratio and hide what doesn't fit.
这篇关于裁剪UIImage以适合帧图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!