I have one "room" image.
Now, user will click on any particular color suppose blue color in image.
And also user will select replaced color like "black" color.
So, all "blue" color inside the image will be replaced by "black" color.
Any one have idea for how to achieve this in iPhone?
Help is appreciated.
You'll need access to the raw pixel data somehow (see this answer or user Krishnabhadra's code). Search through all the pixels and eg for blue->black replacement, replace all blue pixels with black. Look at converting the colour to HSV which will make the colour replacement calculation easier.
I modified a little of Krishnabhadra's's code, since I'm using RGB for color input as well as output e.g:
[UIColor colorWithRed:191.0f/255.0f green:30.0f/255.0f blue:45.0f/255.0f alpha:1.0f]
Works for me.
Wrote a function from memory..errors possible..correct yourself
I hope you are not calling this function every time...It is a bit processor heavy..And if I was your processor, I wouldn't be happy with you..:)
I stumbled in this answer searching for replacing a color with another. Well, since that I need for Swift code, I have had several try and I find a nice solution. Thanks @Rob for its answer.
Where RGBA32 struct is simply:
In this way , wherever in your code:
(*) creating image with color is explained here.