如何在iphone上的新UIImage上渲染径向渐变 [英] How to render a radial gradient onto a new UIImage on an iphone

查看:207
本文介绍了如何在iphone上的新UIImage上渲染径向渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道如何将径向渐变(点>圆)渲染到新的UIImage(iphone)上。
我看到以下内容:

Just wondering how to render a radial gradient (point > circle) onto a new UIImage (iphone). I saw the following:

http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_shadings/dq_shadings.html

它让我觉得我需要使用CGShadingRef或CGGradientRef,并使用UIImage的'imageWithCGImage'构造函数从CG *转到UIImage ...但我无法弄清楚如何。

And it made me think i need to use CGShadingRef or CGGradientRef, and use UIImage's 'imageWithCGImage' constructor to go from the CG* to a UIImage... but i can't figure out how.

任何建议都非常感谢!

推荐答案

你应该阅读关于图形上下文与您链接的部分相同的文档。所有绘图都在图形上下文中进行。如果要创建具有径向渐变或线性渐变或其他任何内容的图像,则需要:

You should read about Graphics Contexts in the same document as the section you linked. All drawing happens in a graphics context. If you want to create an image that has a radial gradient, or a linear gradient, or anything else, you'll need to:

  • Create a graphics context for your image with UIGraphicsBeginImageContextWithOptions.
  • Do whatever drawing you want to appear in the image.
  • Call UIGraphicsGetImageFromCurrentImageContext to get the image from the context. This gives you a UIImage, so no need to convert from a CGImage.
  • Call UIGraphicsEndImageContext to clean up the context.

这篇关于如何在iphone上的新UIImage上渲染径向渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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