Note that there are some explanatory texts on larger screens.

plurals
  1. POCALayer and CGGradientRef anti-aliasing?
    primarykey
    data
    text
    <p>I'm having an odd issue with CALayer drawing for the iPhone. I have a root layer which adds a bunch of sublayers representing "bubbles". The end result is supposed to look something like this:</p> <p><a href="http://www.expensivedna.com/IMG_0018.PNG" rel="nofollow noreferrer">http://www.expensivedna.com/IMG_0018.PNG http://www.expensivedna.com/IMG_0018.PNG</a></p> <p>The problem is that I can't seem to get the layer to anti-alias (notice the jaggies on the bubbles). My code overwriting drawInContext for the bubble CALayer is as follows:</p> <pre><code>- (void)drawInContext:(CGContextRef)theContext{ CGContextSetAllowsAntialiasing(theContext, true); CGContextSetShouldAntialias(theContext, true); size_t num_locations = 2; CGFloat locations[2] = { 0.0, 1.0 }; CGFloat components[8] = { 1.0, 1.0, 1.0, 0.5, // Start color 1.0, 1.0, 1.0, 0.0 }; // End color CGColorSpaceRef rgbColorspace = CGColorSpaceCreateDeviceRGB(); CGGradientRef glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations); CGPoint topCenter = CGPointMake(25, 20); CGPoint midCenter = CGPointMake(25, 25); CGContextDrawRadialGradient(theContext, glossGradient, midCenter, 20, topCenter, 10, kCGGradientDrawsAfterEndLocation); </code></pre> <p>}</p> <p>Now the really odd thing is that if I slightly alter the drawing code to only draw normal red circles as follows:</p> <pre><code>- (void)drawInContext:(CGContextRef)theContext{ CGContextSetAllowsAntialiasing(theContext, true); CGContextSetShouldAntialias(theContext, true); CGContextSetFillColorWithColor(theContext, [UIColor redColor].CGColor); CGContextFillEllipseInRect(theContext, CGRectMake(0, 0, 40,40)); } </code></pre> <p>Everything seems to antialias OK:</p> <p><a href="http://www.expensivedna.com/IMG_0017.PNG" rel="nofollow noreferrer">http://www.expensivedna.com/IMG_0017.PNG http://www.expensivedna.com/IMG_0017.PNG</a></p> <p>I can't seem to figure out this seemingly odd behavior. Am I missing some difference between antialiasing gradients and normal circles?</p> <p>Thanks guys.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload