Dmitry
Dmitry

Reputation: 7340

CAShapeLayer disable antialiasing

I'm making a "marching ants" selection frame with Core Animation Layers like in this post: MARCHING ANTS WITH CORE ANIMATION. But the only thing I don't like is the width of line in CAShapeLayer. I need the width to be exactly 1px, but because of antialiasing the line width is about 2 pixels and a little transparent.

Is there any way to turn off antialiasing?

Upvotes: 2

Views: 1233

Answers (2)

Gordon Dove
Gordon Dove

Reputation: 2577

I came across the same problem, fortunately, I wandered around a bit more and found the CGContextSetShouldAntialias( GCContextRef, BOOL) function. It turns out that the antialiasing was happening in the Graphics Context.

I tested this with a series of shape layers under a CALayer rendering into a bitmap context. By default, I got the values I set in the range 100-130 ( bitmap values), and a bunch of lower numbers. After setting CGContextSetShouldAlias( context, NO), I got just my values.

Upvotes: 6

Duncan C
Duncan C

Reputation: 131418

Based on the docs, it looks like you're stuck with antialising:

The CAShapeLayer class draws a cubic Bezier spline in its coordinate space. The shape is composited between the layer's contents and its first sublayer.

The shape will be drawn antialiased, and whenever possible it will be mapped into screen space before being rasterized to preserve resolution independence. However, certain kinds of image processing operations, such as CoreImage filters, applied to the layer or its ancestors may force rasterization in a local coordinate space.

Upvotes: 4

Related Questions