请教一下 CGContextDrawRadialGradient 绘制径向渐变的参数是啥意思啊 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
adow
V2EX    iDev

请教一下 CGContextDrawRadialGradient 绘制径向渐变的参数是啥意思啊

  •  
  •   adow
    adow 2012 年 12 月 12 日 8942 次点击
    这是一个创建于 4868 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Paints a gradient fill that varies along the area defined by the provided starting and ending circles.

    void CGContextDrawRadialGradient(
    CGContextRef context,
    CGGradientRef gradient,
    CGPoint startCenter,
    CGFloat startRadius,
    CGPoint endCenter,
    CGFloat endRadius,
    CGGradientDrawingOptions options
    );
    Parameters
    context
    A Quartz graphics context.
    gradient
    A CGGradient object.
    startCenter
    The coordinate that defines the center of the starting circle.
    startRadius
    The radius of the starting circle.
    endCenter
    The coordinate that defines the center of the ending circle.
    endRadius
    The radius of the ending circle.
    options
    Option flags (kCGGradientDrawsBeforeStartLocation or kCGGradientDrawsAfterEndLocation) that control whether the gradient is drawn before the starting circle or after the ending circle.
    Discussion
    The color at location 0 in the CGGradient object is mapped to the circle defined by startCenter and startRadius. The color at location 1 in the CGGradient object is mapped to the circle defined by endCenter and endRadius. Colors are linearly interpolated between the starting and ending circles based on the location values of the gradient. The option flags control whether the gradient is drawn before the start point or after the end point.

    startCenter和endCenter 应该是径向渐变的圆心的位置吗,那startRadius和endRadius 的开始和结束的半径是什么意思?

    画出来的怎么感觉和我想的不一样啊?

    我想绘制一个从屏幕中心到周边的由白色到黑色的渐变


    CGContextRef cOntext= UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);

    CGGradientRef myGradient;
    CGColorSpaceRef myColorspace;
    size_t num_locatiOns= 2;
    CGFloat locations[2] = { 0.0, 1.0 };
    CGFloat components[8] = { 1.0,1.0,1.0, 1.0, // Start color
    0.0,0.0,0.0,1.0 }; // End color

    myColorspace = CGColorSpaceCreateDeviceRGB();
    myGradient = CGGradientCreateWithColorComponents (myColorspace, components,
    locations, num_locations);
    CGPoint myStartPoint={rect.size.width/2,rect.size.height/2}, myEndPoint={rect.size.width,rect.size.height};
    CGFloat myStartRadius=0, myEndRadius=rect.size.width;
    CGContextDrawRadialGradient (context, myGradient, myStartPoint,
    myStartRadius, myEndPoint, myEndRadius,
    kCGGradientDrawsAfterEndLocation);

    CGContextRestoreGState(context);
    CGColorSpaceRelease(myColorspace);
    CGGradientRelease(myGradient);
    3 条回复    1970-01-01 08:00:00 +08:00
    doskoi
        1
    doskoi  
       2012 年 12 月 12 日   1
    void CGContextDrawRadialGradient(
    CGContextRef context,
    CGGradientRef gradient, //先创造一个CGGradientRef,颜色是白,黑,location分别是0,1
    CGPoint startCenter, // 白色的起点(中心圆点)
    CGFloat statRadius, // 起点的半径,这个值多大,中心就是多大一块纯色的白圈
    CGPoint endCenter, // 白色的终点(可以和起点一样,不一样的话就像探照灯一样从起点投影到这个终点,按照你的意图应该和startCenter一样
    CGFloat endRadius, //终点的半径, 按照你的意图应该就是从中心到周边的长
    CGGradientDrawingOptions options //应该是 kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation
    );
    doskoi
        2
    doskoi  
       2012 年 12 月 12 日
    adow
        3
    adow  
    OP
       2012 年 12 月 12 日
    这回懂了,谢谢@doskoi
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2921 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 02:53 PVG 10:53 LAX 19:53 JFK 22:53
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86