我正在将我的上下文剪切成三角形,当我在该三角形内绘制图像时,我会看到锯齿状边缘。它们在视网膜显示器上看起来很糟糕(还没有在其他设备上测试过)。我试图将我的应用程序的.plist文件中的UIViewEdgeAntialiasing
设置为YES
,并确保为我的上下文启用抗锯齿功能。
这是代码:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetAllowsAntialiasing(context, YES);
CGContextSetShouldAntialias(context, YES);
CGContextSaveGState(context);
CGContextSetShadowWithColor(context, CGSizeMake(1, 1), 3, UIColorFromRGB(0x000000, 0.12).CGColor);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGMutablePathRef rightCornerCutOut = CGPathCreateMutable();
CGPathMoveToPoint(rightCornerCutOut, NULL, self.offset, self.offset);
CGPathAddLineToPoint(rightCornerCutOut, NULL, self.cutOutSize-self.offset, self.offset);
CGPathAddLineToPoint(rightCornerCutOut, NULL, self.offset, self.cutOutSize-self.offset);
CGPathCloseSubpath(rightCornerCutOut);
CGContextAddPath(context, rightCornerCutOut);
CGContextFillPath(context);
CGContextAddPath(context, rightCornerCutOut);
CGContextClip(context);
CGRect imgRect = CGRectMake(0,0,self.cutOutSize,self.cutOutSize);
[myImage drawInRect:imgRect];
CGContextRestoreGState(context);