Question

J'ai un UIImage avec canal alpha.

Comment extraire les canaux RVB d'un UIImage, chacun d'eux étant un UIImage indépendant avec alpha?

merci d'avance.

Était-ce utile?

La solution

Comme ceci .

Consultez également cette question - troisième réponse en détail paranoïaque
Et du code pour accéder aux pixels et les sauvegarder dans un nouveau UIImage:

UIImage* image = ...; // An image
NSData* pixelData = (NSData*) CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage));
void* pixelBytes = [pixelData bytes];

//Leaves only the green pixel, assuming 32-bit RGBA
for(int i = 0; i < [pixelData length]; i += 4) {
        bytes[i] = 0; // red
        bytes[i+1] = bytes[i+1]; // green
        bytes[i+2] = 0; // blue
        bytes[i+3] = 0; // alpha
    }

NSData* newPixelData = [NSData dataWithBytes:pixelBytes length:[pixelData length]];
UIImage* newImage = [UIImage imageWithData:newPixelData];

adapté de ici . Pour avoir les trois canaux distincts dans des images séparées, procédez comme dans le code, définissez la valeur sur zéro sauf le canal que vous souhaitez enregistrer à chaque fois, puis créez la nouvelle image.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top