문제

I'm using such solution to mask my UIImage with some alpha drawing: masking an UIImage

The problem is that later i want to apply some CIFilters. However when i change value of the filter, my alpha gets lost from UIImage. Do i have to re-apply the alpha channel to output image each time after modifying CIFilter? This will surely make the process much slower.

Samples of code: (each new paragraph is in another method)

// set the image
_image = [incomeImage imageWithMask:_mask]; // imageWithMask from method from link
[_myView.imageView setImage:_image];

// calculate ciimages
_inputCIImage = [[CIImage alloc] initWithCGImage:_image.CGImage options:nil];
_myView.imageView.image = _image;
_currentCIImage = _inputCIImage;

// change value in filter
[filter setValue:@(0.2f) forKey:@"someKey"];
[filter setValue:_inputCIImage forKey:kCIInputImageKey];
_currentCIImage = [filter outputImage];
CGImageRef img = [_context createCGImage:_currentCIImage fromRect:[_currentCIImage extent]];
UIImage *newImage = [UIImage imageWithCGImage:img];
도움이 되었습니까?

해결책

you could do this only using CIFilters. Instead of using imageWithMask you can use the CIBlendWithMask CIFilter. Apple CIFilter Reference

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top