Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to mask an image in IOS sdk?
    primarykey
    data
    text
    <p>I want to apply an image filter or mask when a word drawn on the image.The word will have transparent effect to see through the background image. Is it possible in native IOS sdk or i need different api to perform this. This image consist of 2 images. one is where India is written over, and another one is which is see through India letter.<img src="https://i.stack.imgur.com/Bu3PG.png" alt="This image consist of 2 images. one is where India is written over, and another one is which is see through the India letter."></p> <p>This is the code i am using to generate image from text.</p> <pre><code>-(UIImage *)imageFromText:(NSString *)text{ // set the font type and size UIFont *font = [UIFont systemFontOfSize:100.0]; CGSize size = [text sizeWithFont:font]; // check if UIGraphicsBeginImageContextWithOptions is available (iOS is 4.0+) if (UIGraphicsBeginImageContextWithOptions != NULL) UIGraphicsBeginImageContextWithOptions(size,NO,0.0); else // iOS is &lt; 4.0 UIGraphicsBeginImageContext(size); // optional: add a shadow, to avoid clipping the shadow you should make the context size bigger // CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetShadowWithColor(ctx, CGSizeMake(0.0, 1.0), 5.0, [[UIColor blackColor] CGColor]); CGContextSetBlendMode(ctx,kCGBlendModeNormal); CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor); /*NSLog(@"Rect %@",CGContextGetClipBoundingBox(ctx)); CGImageRef alphaMask = CGBitmapContextCreateImage(ctx); CGContextClipToMask(ctx, CGContextGetClipBoundingBox(ctx), alphaMask);*/ // draw in context, you can use also drawInRect:withFont: [text drawAtPoint:CGPointMake(0.0, 0.0) withFont:font]; // transfer image UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image;} </code></pre> <p>It is working fine, however i need to generate the image which will have black background and transparent text to see through it.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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