我想使用任何关闭路径裁剪图像,如UIBezierPath。它可以在iPhone应用程序? [英] i want to crop image using any close path like UIBezierPath. it is possible in iPhone application?

查看:201
本文介绍了我想使用任何关闭路径裁剪图像,如UIBezierPath。它可以在iPhone应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用任何关闭路径(如UIBezierPath)在我的iPhone应用中裁剪图像。我知道有可能使用矩形,但我想要不同形状的裁剪。就像我使用触摸制作一个形状,并希望裁剪图像,以便如何实现。
任何建议或帮助。
提前致谢。

i want to crop image in my iPhone app using any close path like UIBezierPath. i know it is possible using rectangle but i want crop in different shape. like i make one shape using touch and want to crop that image so how it is possible. any suggestion or help. Thanks in advance.

推荐答案

您可以使用shapelayer裁剪图像。要做到这一点,你必须创建一个路径,用作新图像的边框。你应该看一下这个问题

You can crop your image with a shapelayer. To do it you have to create a path that will be used as borders for your new image. You should look at this question.

CALayer* contentLayer = [CALayer layer];
[contentLayer setFrame:CGRectMake(0, 0, 80, 80)];
CAShapeLayer* mask = [CAShapeLayer layer];

CGMutablePathRef path = CGPathCreateMutable();

CGPathMoveToPoint(path, NULL, 10, 10);
CGPathAddLineToPoint(path, NULL, 10, 80);
CGPathAddLineToPoint(path, NULL, 80, 80);
CGPathAddLineToPoint(path, NULL, 80, 10);
mask.path = path;

[contentLayer setContents:(id)[[UIImage imageNamed:@"image.png"] CGImage]];
[contentLayer setMask:mask];          

[[self layer]addSublayer:contentLayer];

这样的事情。

这篇关于我想使用任何关闭路径裁剪图像,如UIBezierPath。它可以在iPhone应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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