问题描述
是否有 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:
这篇关于MonoTouch:圆润的 UIImage 便捷方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!