0

I am creating an image with UIImage, and overlaying some text on top.

The end result is coming out blurry, and I want it to be clear

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;
}

I have seen others having problems when setting the scale wrong, but changing it doesn't affect mine. Anyone else having similar issues?

mwiggs
  • 157
  • 1
  • 8

0 Answers0