¿Cómo puedo borrar la parte magenta de un UIImage y hacerla transparente?Color iOS a transparente en UIImage
He revisado numerosas respuestas y enlaces en SO y nada funciona (por ejemplo, How to make one color transparent on a UIImage? respuesta 1 quita todo menos rojo, la respuesta 2 aparentemente no funciona debido a Why is CGImageCreateWithMaskingColors() returning nil in this case?).
Actualización:
Si uso CGImageCreateWithMaskingColors con el UIImage consigo un valor nulo. Si elimino el canal alfa (represento la imagen como JPEG y la vuelvo a leer) CGImageCreateWithMaskingColors devuelve una imagen pintada con un fondo negro.
Update2, el código:
Volviendo nil:
const float colorMasking[6] = {222, 255, 222, 255, 222, 255};
CGImageRef imageRef = CGImageCreateWithMaskingColors(anchorWithMask.CGImage, colorMasking);
NSLog(@"image ref %@", imageRef);
// this is going to return a nil imgref.
UIImage *image = [UIImage imageWithCGImage:imageRef];
Volviendo una imagen con el fondo negro (que es normal ya que no hay canal alfa):
UIImage *inputImage = [UIImage imageWithData:UIImageJPEGRepresentation(anchorWithMask, 1.0)];
const float colorMasking[6] = {222, 255, 222, 255, 222, 255};
CGImageRef imageRef = CGImageCreateWithMaskingColors(inputImage.CGImage, colorMasking);
NSLog(@"image ref %@", imageRef);
// imgref is NOT nil.
UIImage *image = [UIImage imageWithCGImage:imageRef];
Update3:
Lo conseguí trabajando agregando el canal alfa después del proceso de enmascaramiento.
publicar su código. –
Agregó el código. –