简体   繁体   English

iPhone:如何去除图像中的红色? (RGB色彩)

[英]iphone: How can I remove the red colors from an image? (RGB colors)

Let's say I have an UIImageView, and I wanna show only blue and green colore from it, (RGB colors). 假设我有一个UIImageView,我只想显示其中的蓝色和绿色(RGB颜色)。 Like in Photoshop, I can choose what colors to show, red, blue, and green, so in the image to delete the red color. 像在Photoshop中一样,我可以选择显示红色,蓝色和绿色的颜色,因此可以在图像中删除红色。

So how can I do it? 那我该怎么办呢? I really new in Objective-c and all :) 我真的在Objective-c和所有方面都是新手:)

There are many ways to do this. 有很多方法可以做到这一点。 If you have access to the image bitmap data, you can just set the red channel to zero on all the pixels. 如果可以访问图像位图数据,则可以将所有像素上的红色通道设置为零。 You might need to draw the image into a CGBitmapContext, get the pointer to the bitmap data, and then create a new CGImage that gets turned into a UIImage. 您可能需要将图像绘制到CGBitmapContext中,获取指向位图数据的指针,然后创建一个新的CGImage并将其转换为UIImage。

Or you can create a UIView subclass with a custom drawRect: method which first draws the image normally, and then draws a color set to RGB (0, 1, 1) with the blend mode (set by CGContextSetBlendMode) to kCGBlendModeMultiply. 或者,您可以使用自定义drawRect:方法创建UIView子类,该方法首先正常绘制图像,然后将混合模式(由CGContextSetBlendMode设置)的颜色设置为RGB(0,1,1)设置为kCGBlendModeMultiply。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM