更改图像颜色 [英] Change Color of Image
本文介绍了更改图像颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个32bpp的黑白图像,但是我想将其颜色更改为某种特定的颜色,例如红色或绿色...我搜索并测试了许多.net应用程序,但是'em都无法做到这一点.因此,有什么想法吗?
I''ve a black and white image with 32-bpp but I want to change its color to some specific like red or green...I searched and tested many .net applications but none of ''em could do that. So any idea ?
推荐答案
没有真正的方法可以准确地做到这一点,因为灰度图像已丢弃了颜色信息.您可以很容易地进行颜色清洗,我的图像处理文章介绍了如何做到这一点,但是您不会将灰度转换回真实,准确的颜色.
There is no real way to do this accurately, a greyscale image has discarded color info. You can do a color wash easy enough, my image processing articles show how to do that, but you won''t turn greyscale back into real, accurate color.
注意:这仅仅是安全代码,而且速度会很慢.稍后我将其更改为不安全,但以下代码仅用于显示该想法;).
NOTE : This is just safe code and will be slow. I will change it to unsafe later but the following code is just for showing the idea ;).
void ChangeColor(Bitmap image)
{
for (int x = 0; x < image.Width; x++)
{
for (int y = 0; y < image.Height; y++)
{
Color c = image.GetPixel(x, y);
Color nc = Color.FromArgb(c.A, c.R, 0, 0);
image.SetPixel(x, y, nc);
}
}
}
这篇关于更改图像颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文