将图像内的特定颜色替换为另一种颜色
我有一个“房间”图像。
现在,用户将单击任何特定颜色(假设图像中为蓝色)。
用户还将选择替换颜色,例如“黑色”颜色。
因此,图像内的所有“蓝色”颜色将被“黑色”颜色替换。
有人知道如何在 iPhone 中实现这一目标吗?
感谢帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
检查它的 rgb值
将像素值更改为您的 toColor rgb 值。如果没有,请离开
该像素并转到下一个..
从内存中编写了一个函数..可能存在错误..自己纠正我
希望你不要每次都调用这个函数...它有点处理器繁重..如果我是你的处理器,和你在一起我会不高兴..:)
values
change the pixel value to your toColor rgb values.If not, just leave
that pixel and go to next one..
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..:)
我偶然发现这个答案,寻找用另一种颜色替换一种颜色的方法。
好吧,因为我需要 Swift 代码,所以我进行了多次尝试,并找到了一个不错的解决方案。感谢 @Rob 的回答。
RGBA32 结构很简单:
以这种方式,在代码中的任何位置:
(*) 使用颜色创建图像的解释这里。
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.
您需要以某种方式访问原始像素数据(请参阅这个答案或用户 Krishnabhadra 的代码)。搜索所有像素,并且例如对于蓝->黑替换,用黑色替换所有蓝色像素。查看将颜色转换为 HSV,这将使颜色替换计算更容易。
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.
我修改了一些 Krishnabhadra 的代码,因为我使用 RGB 进行颜色输入和输出,例如:
[UIColor colorWithRed:191.0f/255.0f green:30.0f/255.0f blue:45.0f/255.0f alpha:1.0f ]
对我有用。
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.