MonoTouch:圆润的 UIImage 便捷方法 [英] MonoTouch: Rounded UIImage Convenience Method

查看:22
本文介绍了MonoTouch:圆润的 UIImage 便捷方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有 MonoTouch 内置方法来圆化 UIImage 的边缘?

Is there a MonoTouch built-in method to round the edges of a UIImage ?

我好像记得看过一次.

推荐答案

舍入一个 UIImage 会产生另一个 UIImage.

Rounding a UIImage would produce another UIImage.

如果您创建一个 CGContext 以与原始图像的大小相同的大小进行渲染,然后添加带有圆角的剪切路径并渲染您的原始 UIImage,则可以执行此操作.

You can do this if you create a CGContext to render into with the same size as the original image, then add a clipping path with the rounded corners and rendering your original UIImage.

然后就可以将 UIImage 从 CGContext 中拉出来了.

Then you can pull the UIImage out of the CGContext.

另一种选择是避免中间步骤,是在上下文绘制中推送图形状态,添加圆形路径作为剪切路径,绘制图像然后弹出图形状态返回到此.

Another option is to avoid the intermediate step, is to push the graphics state in your context drawing, add the rounded path as a clipping path, draw the image and then pop the graphics state to go back to this.

您可以看到 TweetStation 如何将其用于其玻璃按钮:

You can see how TweetStation uses this for its Glass Buttons:

https://github.com/migueldeicaza/MonoTouch.Dialog/blob/master/MonoTouch.Dialog/Utilities/GlassButton.cs#L76

这篇关于MonoTouch:圆润的 UIImage 便捷方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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