I want to exchange a particular color inside an image with another color. Is there any possible way? - iphone

I have one image with multiple colors.
I want to change a specific color with the alternate color that i have pre-decided.
Is there any algorithms to modify the image and save it?
Help is appreciated.
Thank you very much.

See the selected answer to this question:
How to make one color transparent on a UIImage?
It also shows turning red pixels green, which applies to your question.

Definatly yes.
Look here
Bitmap Images and Image Masks
Look in that page for: "Masking with color"

Related

Create tintable image with solid colour, so that it can adapt Dark and Light modes

I need to create UIImage (bitmap?) filled with a solid colour so that it can be tinted and thus support Dark and Light mode changes
Is there a way to do this in Swift?
Not the best way, but a quick and dirty way to do this would be make a UIView with a background the color you want and then use one of the many ways to go UIView -> UIImage.
This stack overflow question here does exactly that:
How to convert a UIView to an image
Furthermore, looking at that code will give you some insights on how to do it the right way, with lower level graphics functions if you like.

how to fill color in image in particular area?

I want to fill the color in white area for Paint based application so please give me suggestion for how to do this work.
GPUImage is what you need there is a bunch of filters. In principle you need to point ios that it needs to change all whitecolors RGB(255.0,255.0,255.0) to some other color.

Changing the particular color in an image

By using the following image i want to write code.
here is the image i want to do this one programmatically.
User can select roof or wall or fencing or windows. After selecting the particular part and color(another model) then the present color(another model) should replace with selected color.
In this image(example) user selected color(yellow) for wall and brown color for roof, after selection of color and part, old color should replace with new one.
How can we achieve this
any suggestions or help
Check my answer of how you can change the specific colors of UIImage.
Two notes:
the question is about gray to white color change, you can use this technique to change any color to any other,
the code is taken from somewhere of the developers reference, so that colors in the snippet are kinda random.

Why images in XIB are different?

At left there's the original image (after imported in Xcode), at right the image inside UIImageView. It's more dark.
Why this? It's a very annoying problem.
Man! Its just an illusion.
Don't ask "magic" related questions here. Ask only program related questions ;-)
Both images are of same color. They look different because their background colors are different. Use Photoshop or some other tool to find the colors of those two. They should be the same.
Its because the background colours are different and the stroke on the image is the same / similar colour to the background.
Change the background colour of the view to white, and it will look normal.

Can i specify a color to be transparent

I have a UIImage, the background of it is white. I want the background of this UIImage to be transparent to its parent view. Is this possible?
One word answer- No. As robin said you have to use photo editing softwares to accomplish that. it cannot be done iphone(easily)..
I am not going to suggest that it is easy, but you should take a look at CGImageCreateWithMaskingColors, which is described in the Quartz 2D Programming Guide: Bitmap Images and Image Masks
You can't specify the transparency of a color from an image, but you could make a PNG image which has a transparency in the places you want it to be transparent.