选择图像的一部分(剪辑)
这可能不像我想象的那么难,但是如何选择图像的一部分?考虑以下示例:
灰色区域是PNG或JPG格式的图像,现在我想从中选择红色的80x80像素区域。红色区域应该显示,其余区域不显示。我尝试了多种方法:
- 将 UIImageView 的 ClipsToBounds 设置为 YES 并尝试偏移图像(不起作用)
- 剪辑上部视图(不起作用)
我也查看了绘图功能,但还没有工作还没有这些,对我来说似乎有点牵强。有没有什么明显的方法可以做我想做但我错过的事情?我不想调整图像大小,只是剪裁。
感谢您抽出时间!
This is probably not as hard as I think it is, but how can I select part of an image? Consider the following example:
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:
- Make clipsToBounds of UIImageView to YES and the try to offset the image (doesn't work)
- Clip the upper view (doesn't work)
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.
Thanks for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从这个问题中窃取以下代码并寻找 HitScan 的答案。
Stole the code below from this question and look for HitScan's answer.
如果您只想显示图像的中心,则可以通过 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.Or in code
请参考下面的代码。在这里,我提供一个图像视图并将其分成两个相等的图像视图。
Refer to the code below. Here i am providing an imageview and splitting the same in two equal imageviews.