Make the image black and white?

I have another quartz 2d (iphone) question:

How to change all ImageView colors to black and white and leave only red ???

DD

+3
source share
1 answer
UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];  this image we get from UIImagePickerController

    CGColorSpaceRef colorSapce = CGColorSpaceCreateDeviceGray();
    CGContextRef context = CGBitmapContextCreate(nil, originalImage.size.width, originalImage.size.height, 8, originalImage.size.width, colorSapce, kCGImageAlphaNone);
    CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
    CGContextSetShouldAntialias(context, NO);
    CGContextDrawImage(context, CGRectMake(0, 0, originalImage.size.width, originalImage.size.height), [originalImage CGImage]);

    CGImageRef bwImage = CGBitmapContextCreateImage(context);
    CGContextRelease(context);
    CGColorSpaceRelease(colorSapce);

    UIImage *resultImage = [UIImage imageWithCGImage:bwImage]; // This is result B/W image.
    CGImageRelease(bwImage);

This is what I found on other forums, AND THIS WATCH THE WORK !!!

+15
source

Source: https://habr.com/ru/post/1760514/


All Articles