循环UIImageView:最佳性能?

时间:2015-04-16 06:42:19

标签: ios objective-c uiimageview uibezierpath

我需要从UIImageView的矩形图像生成圆形图像。目前我正在使用Bezier路径绘制它:

+ (UIImage *)jsq_circularImage:(UIImage *)image withDiameter:(NSUInteger)diameter highlightedColor:(UIColor *)highlightedColor
{
    NSParameterAssert(image != nil);
    NSParameterAssert(diameter > 0);

    CGRect frame = CGRectMake(0.0f, 0.0f, diameter, diameter);
    UIImage *newImage = nil;

    UIGraphicsBeginImageContextWithOptions(frame.size, NO, [UIScreen mainScreen].scale);
    {
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSaveGState(context);

        UIBezierPath *imgPath = [UIBezierPath bezierPathWithOvalInRect:frame];
        [imgPath addClip];
        [image drawInRect:frame];

        if (highlightedColor != nil) {
            CGContextSetFillColorWithColor(context, highlightedColor.CGColor);
            CGContextFillEllipseInRect(context, frame);
        }

        newImage = UIGraphicsGetImageFromCurrentImageContext();

        CGContextRestoreGState(context);
    }
    UIGraphicsEndImageContext();

    return newImage;
}

这种方法的问题在于它的性能非常不理想(对于小图像大约需要0.3秒)。

在向视图应用旋转动画时,我无法将cornerRadiusclipToBounds一起使用。

除了预处理原始图像以使其成为圆形之外,还有其他选择吗?

0 个答案:

没有答案