如何将一组颜色的“阴影”替换为另一组 [英] How to replace one set of color 'shades' with another set

查看:227
本文介绍了如何将一组颜色的“阴影”替换为另一组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一个魔法函数,它将获取一个图像并返回一个副本,但一组颜色深浅被替换为另一个颜色深浅。

I'm looking for a 'magic' function that will take an image and return a copy but with one set of color shades replaced with another set.

我有一条红鱼的图片:它有各种灰度和黑白,但本质上是各种各样的红色。我想把它传递给这个魔术的功能,并告诉它改变其Color.Red阴影等同于Color.Yellow阴影等。只是简单的(彩虹)颜色就够了。

e.g. I have a picture of a Red fish: It has various greyscales and Black and White but is essentially various shades of red. I would like to pass it to this 'magic' function and tell it to change its Color.Red shades to equivalent Color.Yellow shades and so on. Just simple (rainbow) colors would be sufficient.

我在网上看到很多代码片段,但他们似乎集中在用另一种颜色代替一种颜色,

I have seen many code snippets here and on the internet but they seem to concentrate on replacing a single color with another or using a threshold, which works well enough interactively but isn't quite magic enough.

我想要应用此图片的图片不是照片或任何太复杂的图片,简单精灵等。

The images I want to apply this to are not photographs or anything too complicated, just icons or simple sprites and the like. (I'm just bored of creating copies in an image editor!)

任何人都有这样的东西吗?

Anyone have anything like this?

推荐答案

您可以使用 FromAhsb() com / questions / 3837449 / image-hue-modification-in-c-sharp> C#中的图像色调修改(或任何其他允许从HSB值创建颜色的函数)。使用此功能,您可以轻松地更改图像的色调如下:

You can accomplish this using the FromAhsb() as displayed in Oliver's answer at Image hue modification in C# (or any other function which lets you create colors from HSB values). Using this function you can easily change the hue of images as following:

var image = new Bitmap("D:\\fish.png"); // location of your image
var color = Color.Red; //The color in the hue you want to change the image.

for (var x = 0; x < image.Width; x++)
{
    for (int y = 0; y < image.Height; y++)
    {
        Color originalColor = image.GetPixel(x, y);
        Color changedColor = FromAhsb(originalColor.A, color.GetHue(), originalColor.GetSaturation(), originalColor.GetBrightness());
        image.SetPixel(x,y, changedColor);
    }
}

image.Save("D:\\new_fish.png", System.Drawing.Imaging.ImageFormat.Png); // location of your new image

这会产生以下结果:

From


From to

这篇关于如何将一组颜色的“阴影”替换为另一组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆