在CGMutablePath中绘制UIImage [英] drawing UIImage inside a CGMutablePath

查看:130
本文介绍了在CGMutablePath中绘制UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于CGMutablePathRef如何在其中绘制UIImage?我知道您可以像下面那样绘制它:

Given a CGMutablePathRef how do I draw a UIImage in it? I know that you can draw it like the following:

 UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        [scaledImage drawAtPoint:CGPointMake(0, 0)];
        CGContextRestoreGState(context);

但我不确定我是否有路径(这是一个带圆角的矩形)怎么做我在其中添加了一个图像?

but I am not sure if I have a path (which is a rectangle with rounded corner) how do I add an image in it?

推荐答案

当你说在CGMutablePath中绘制时,我必须假设你的意思是剪辑 CGMutablePath。在这种情况下,您只需要添加当前上下文的路径( CGContextAddPath()或任何路径构建函数,如 CGContextAddLineToPoint() )然后调用 CGContextClip()。然后,您可以在上下文中使用类似 drawAtPoint: CGContextDrawImage()的方式绘制图像。

When you say "draw within a CGMutablePath" I have to assume you mean "clip to a CGMutablePath." In that case, you just need to add the path to the current context (CGContextAddPath() or any of the path-building functions like CGContextAddLineToPoint()) and then call CGContextClip(). You can then draw your image in the context with something like drawAtPoint: or CGContextDrawImage().

这篇关于在CGMutablePath中绘制UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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