Quiero aplicar un filtro de imagen o máscara cuando una palabra se dibuja en la imagen. La palabra tendrá un efecto transparente para ver a través de la imagen de fondo. ¿Es posible en SDK nativo de IOS o necesito api diferente para realizar esto? Esta imagen consiste en 2 imágenes. una es donde está escrita la India, y otra es la carta de India. ¿Cómo enmascarar una imagen en IOS SDK?
Este es el código que estoy usando para generar imágenes a partir de texto.
-(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 < 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;}
Se está trabajando muy bien, sin embargo lo que necesito para generar la imagen que tendrá el fondo negro y texto transparente para ver a través de él.
gracias chicos. esta funcionando. 2 imágenes todo lo que necesitamos es una imagen enmascaradora con fondo negro y una carta incrustada y otra es una imagen original en la que funcionará la máscara. ¿Podría ser posible hacer la imagen de enmascaramiento dinámicamente desde el código? – arindam