Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I create a template image to be colored at run time
    primarykey
    data
    text
    <p>I have an image that is an almost flat color. It's attached but, plain white so you can't see it easily.</p> <p><img src="https://i.stack.imgur.com/ZsTV3.png" alt="Sample image"> I would like to be able to dynamically color this image at runtime, but I need to do it in iOS 6 without using UIImageRenderingModeAlwaysTemplate.</p> <p>The images will all start plain white with minor gradients for rounded corners.</p> <p>So far my best attempt has been using GPUImage and a category on UIImage</p> <pre><code>@implementation UIImage (BPAdditions) - (UIImage *)imageWithColor:(UIColor *)color { GPUImageRGBFilter *stillImageFilter = [[GPUImageRGBFilter alloc] init]; CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha =0.0; [color getRed:&amp;red green:&amp;green blue:&amp;blue alpha:&amp;alpha]; stillImageFilter.red = red; stillImageFilter.green = green; stillImageFilter.blue = blue; GPUImageChromaKeyFilter *stillImageFilter2 = [[GPUImageChromaKeyFilter alloc] init]; [stillImageFilter2 setColorToReplaceRed:0 green:0 blue:0]; stillImageFilter2.thresholdSensitivity = 0.2; stillImageFilter2.smoothing = 0; UIImage *img = [stillImageFilter imageByFilteringImage:self]; return [stillImageFilter2 imageByFilteringImage: img]; } </code></pre> <p>This would be ideal, except when I used the RGB filter it turns the clear background black. Then removing this with the chroma filter has varying quality depending on the color used.</p> <p>There is a possibility that the target color will be black, in which case this solution will fail entirely.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload