如何重新着色图像? (见图) [英] How do I recolor an image? (see images)
本文介绍了如何重新着色图像? (见图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何以编程方式实现这种颜色替换?
How do I achieve this kind of color replacement programmatically?
这是我用来替换像素的函数:
So this is the function I have used to replace a pixel:
Color.FromArgb(
oldColorInThisPixel.R + (byte)((1 - oldColorInThisPixel.R / 255.0) * colorToReplaceWith.R),
oldColorInThisPixel.G + (byte)((1 - oldColorInThisPixel.G / 255.0) * colorToReplaceWith.G),
oldColorInThisPixel.B + (byte)((1 - oldColorInThisPixel.B / 255.0) * colorToReplaceWith.B)
)
谢谢你,CodeInChaos!
Thank you, CodeInChaos!
推荐答案
新像素是:
newColor.R=OldColor;
newColor.G=OldColor;
newColor.B=255;
泛化为任意颜色:
假设您想将白色映射到白色,将黑色映射到该颜色。所以公式是 newColor = TargetColor +(White-TargetColor)* Input
I assume you want to map white to white and black to that color. So the formula is newColor=TargetColor+(White-TargetColor)*Input
newColor.R=OldColor+(1-oldColor/255.0)*TargetColor.R;
newColor.G=OldColor+(1-oldColor/255.0)*TargetColor.G;
newColor.B=OldColor+(1-oldColor/255.0)*TargetColor.B;
然后只是遍历图像的像素(字节数组),并将它们写入一个新的RGB数组。有很多线程如何将图像复制到字节数组并操作它。
And then just iterate over the pixels of the image(byte array) and write them to a new RGB array. There are many threads on how to copy an image into a byte array and manipulate it.
这篇关于如何重新着色图像? (见图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文