Comment puis-je effacer la partie magenta d'un UIImage et le rendre transparent?Couleur iOS à transparente dans UIImage
Je l'ai regardé à travers de nombreuses réponses et des liens sur le SO et rien ne fonctionne (par exemple How to make one color transparent on a UIImage? réponse 1 supprime tout, rouge, réponse 2 ne semble pas marché à cause de Why is CGImageCreateWithMaskingColors() returning nil in this case?).
Mise à jour:
Si je CGImageCreateWithMaskingColors avec le UIImage je reçois une valeur nulle. Si je supprime le canal alpha (je représente l'image au format JPEG et la relire) CGImageCreateWithMaskingColors renvoie une image peinte avec un arrière-plan noir.
Update2, le code:
nil retour:
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];
retour d'une image avec un fond noir (ce qui est normal puisqu'il n'y a pas de canal alpha):
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:
Je l'ai fait fonctionner en ajoutant le canal alpha après le processus de masquage.
votre code postal. –
Ajout du code. –