选择图像的一部分(剪辑) [英] select part of image (clipping)
问题描述
这可能不像我想的那么难,但如何选择图像的一部分?请考虑以下示例:
This is probably not as hard as I think it is, but how can I select part of an image? Consider the following example:
灰色区域是PNG或JPG格式的图片,现在我想从中选择红色的80x80像素区域。应显示红色区域,其余不显示。我尝试了许多方法:
The grey area is an image in the PNG or JPG Format, now I want to select the red 80x80 px area from it. The red area should be displayed, the rest not. I have tried numerous approaches:
- 将UIImageView的clipsToBounds设置为YES并尝试偏移图像>
- 剪辑上方视图(不起作用)
我还看了一下绘图函数,但我还没有与这些工作,它似乎有点拖延了我。有什么明显的方式做我想做的,我错过了吗?
I also had a look at the drawing functions, yet I have not worked with these yet and it seemed a little bit far fetched to me. Is there any obvious way for doing what I want to do that I am missing out on? I do not want the image to be resized, just clipped.
推荐答案
感谢您抽出时间!方案
如果只想显示图像的中心,通过IB将 UIImageView
设置为Aspect Fill。
If you only want to show the center of the image an a UIImageView
set the content mode to "Aspect Fill" via IB. That will center it and crop off anything extra.
或在代码中
myImageView.contentMode = UIViewContentModeScaleAspectFill;
这篇关于选择图像的一部分(剪辑)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!