【问题标题】:Blur effect while drawing with Quartz 2D使用 Quartz 2D 绘图时的模糊效果
【发布时间】:2013-10-03 07:19:59
【问题描述】:

我想在绘制这张图片中右边的线时具有模糊效果:

目前,我正在使用以下代码进行绘制,但这只会绘制左侧的图片:

CGContextSetLineWidth(currentContext, thickness);    
CGContextSetLineCap(currentContext, kCGLineCapRound);
CGContextBeginPath(currentContext);
CGContextMoveToPoint(currentContext, x, y);
CGContextAddLineToPoint(currentContext, x, y);
CGContextMoveToPoint(currentContext, x, y);
CGContextStrokePath(currentContext);

请问有什么想法吗?

问候, 亚历山大

【问题讨论】:

    标签: iphone ios ipad core-graphics quartz-graphics


    【解决方案1】:
    CIContext *context = [CIContext contextWithOptions:nil];
    CIImage *inputImage = [[CIImage alloc] initWithImage:@"your image"];
    CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
    [filter setValue:inputImage forKey:kCIInputImageKey];
    [filter setValue:[NSNumber numberWithFloat:9.0f] forKey:@"inputRadius"];
    CIImage *result = [filter valueForKey:kCIOutputImageKey];
    CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]];
    UIImage *blurrImage = [UIImage imageWithCGImage:cgImage];
    

    使用此代码会给您带来模糊效果。

    【讨论】:

    • 感谢您的回答,但我想使用模糊效果进行绘制,而不是在 UIImage 上应用效果。
    • 绘制后,在 CIImage 中渲染。 imageWithCGImage:如果你需要的话。
    • 您可能想改用fromRect:[inputImage extent]。这可以确保blurrImage 与inputImage 大小相同。使用[result extent] 会导致图片尺寸缩小。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    • 2013-08-10
    相关资源
    最近更新 更多