从 CGImage 绘制 CGContext
我想使用 CGImage
中的图块在 CGContext
上进行绘制,我想按指定的顺序绘制。
根据文档这里似乎在图形上下文中绘制图像的唯一方法是
void CGContextDrawImage (
CGContextRef c,
CGRect rect,
CGImageRef image
);
但这没有考虑到我只想绘制源图像的 CGRect 的情况。我需要采取一些技巧才能使这项工作成功吗?
I would like to draw on a CGContext
by using tiles from CGImage
that I would like to draw in a specified order.
According to documentation here it seems that the only method to draw an image in a graphic context is
void CGContextDrawImage (
CGContextRef c,
CGRect rect,
CGImageRef image
);
But this doesn't take in account the case in which I want to draw just a CGRect
of the source image. Do I have to do some tricks to make this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解你的问题,那么你要求在特定的 CGRect 处裁剪图像,如果是这样,那么你需要看看这个方法。
这将返回您一个 CGImageRef ,根据您的需要,我认为这就是您正在寻找的。
If I understand your question correctly then you are asking to crop an image at a particular
CGRect
, if so then you need to take a look at this method.This will return you a
CGImageRef
and according to your need I think this is what you are looking for.这是 Apple 的 Quartz 2D 编程指南:
请注意,
CGImageCreateWithImageInRect
返回一个由您负责释放的引用,因此您需要在完成mySubimage
后执行此操作代码>:This is listing 11-1 from Apple's Quartz 2D Programming Guide:
Note that
CGImageCreateWithImageInRect
returns a reference that you are responsible for releasing, so you'll need to do this when you're done withmySubimage
: