iOS - UIImage创建模糊图像

时间:2014-09-07 18:09:38

标签: ios objective-c uiimage

我正在使用UIImage创建一个图像,并在顶部覆盖一些文本。

最终结果变得模糊,我希望它清楚

UIImage* DrawTextOnImage(NSString *text, UIImage *image)

{
    UIGraphicsBeginImageContextWithOptions(image.size, YES, 0.0);

    [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
    CGRect rect = CGRectMake(10, 50, image.size.width-20, image.size.height-60);

    NSMutableParagraphStyle *paragraph = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    paragraph.lineBreakMode = NSLineBreakByWordWrapping;
    paragraph.alignment = NSTextAlignmentCenter;

    NSShadow *shadow = [NSShadow.alloc init];
    shadow.shadowColor = [UIColor clearColor];

    NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName:[UIFont systemFontOfSize:18], NSParagraphStyleAttributeName:paragraph, NSShadowAttributeName:shadow};

    [text drawInRect:CGRectIntegral(rect) withAttributes:attributes];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return newImage;
}

我看到其他人在设置错误时遇到问题,但更改它并不影响我的。 其他人有类似的问题吗?

0 个答案:

没有答案