Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write to UIImage?
    primarykey
    data
    text
    <p>This code is not working and i do not understand the mistake. Please help. </p> <pre><code> -(UIImage *)addText:(UIImage *)img text:(NSString *)text1 { int w = img.size.width; int h = img.size.height; //lon = h - lon; char* text = (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding]; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); /*UIGraphicsBeginImageContext(self.view.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; CGContextShowTextAtPoint(UIGraphicsGetCurrentContext(), 50, 100, text, strlen(text)); UIImage *viewImage =UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSLog(@"View Image : %@",viewImage);*/ 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];// "05/05/09"; CGContextSelectFont(context, "Arial", 18, kCGEncodingMacRoman); CGContextSetTextDrawingMode(context, kCGTextFill); CGContextSetRGBFillColor(context, 255, 255, 255, 1); //rotate text CGContextShowTextAtPoint(context, 0, 50, text, strlen(text)); CGContextSetTextMatrix(context, CGAffineTransformMakeRotation( -M_PI/4 )); CGContextShowTextAtPoint(context, 50, 100, text, strlen(text)); //UIImage *compositeImage = UIGraphicsGetImageFromCurrentImageContext(); CGImageRef imageMasked = CGBitmapContextCreateImage(context); CGContextRelease(context); CGColorSpaceRelease(colorSpace); NSLog(@"Image : %@",[UIImage imageWithCGImage:imageMasked]); return [UIImage imageWithCGImage:imageMasked]; //return viewImage; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload