简体   繁体   English

如何通过选择区域来裁剪UIImage

[英]How to crop a UIImage by selecting an area

I'm searching for a posibility to crop UIImages. 我正在寻找裁剪UIImages的可能性。 I've found lots of examples via google how to do this, but I want to do a bit more than just croping the image. 我已经通过Google找到了许多示例,但我想做的不只是裁剪图像。

It would be nice if the user can choose which area of the UIImage will be crop. 如果用户可以选择将裁剪UIImage的区域,那就太好了。 In other languages, for example Javascript, there are many plugins to do that. 在其他语言(例如Javascript)中,有许多插件可以做到这一点。 I'm looking to find something like this: 我正在寻找这样的东西:

http://odyniec.net/projects/imgareaselect/ http://odyniec.net/projects/imgareaselect/

Does anybody know if some similar project exists for objective-c? 有人知道针对Objective-C是否存在类似的项目吗? Thank you! 谢谢!

after days of searching I found out that there is no "plugin" which is similar to ImgAreaSelect. 经过几天的搜索,我发现没有类似于ImgAreaSelect的“插件”。 :-( :-(

The best thing I found was this: https://github.com/barrettj/BJImageCropper 我发现的最好的东西是: https : //github.com/barrettj/BJImageCropper

It wasn't very hard to adapt this project to my needs: now I can choose a proportional area with min size. 使这个项目适应我的需求并不难:现在我可以选择一个最小尺寸的比例区域。 :-) :-)

You could always make a black&white mask of this area and then mask the image (white area on mask will result in transparent area on masked image). 您可以始终对此区域进行黑白蒙版,然后对图像进行蒙版(蒙版上的白色区域将在蒙版图像上形成透明区域)。

Link to nice tutorial on how to mask an image . 链接到有关如何遮罩图像的精美教程。

As an addition you could later calculate the miminum square frame that holds complete masked (cropped) image and crop the result - to get rid of excess transparent areas. 另外,您可以稍后计算保留完整蒙版(裁剪)图像并裁剪结果的最小二乘框架,以消除多余的透明区域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM