0

CGContextShowTextAtPoint に渡された NSString をラップして、画像からはみ出さないようにしようとしています。これが私のコードです:

int w = img.size.width;
int h = img.size.height;
CGFloat fMid = 14;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);

CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1);

char* text  = (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding];

CGContextSelectFont(context, "Arial", fMid, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetRGBFillColor(context, 255, 255, 255, 1);
CGContextShowTextAtPoint(context, 0, fMid, text, strlen(text));


CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);

return [UIImage imageWithCGImage:imageMasked]
4

0 に答える 0