采用黑色和白色混浊后产生的色彩 [英] Generating colours after applying opacity of black and white

查看:226
本文介绍了采用黑色和白色混浊后产生的色彩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我甚至不知道该怎么形容我想要的,但在这里不用。假设我有3个文本框,我在第一个进入一些颜色的十六进制代码,我想在它上面应用黑色层,并设置不透明度为50%,并获得第二个文本框产生的颜色。 。同样的事情,但白色的第三个

I don't even know how to describe what I want, but here goes. Assume I have 3 textboxes, and I enter some colour hex code in the first one, I want to apply a black layer on top of it, and have the opacity set to 50% and get the resulting colour in the second text box. Same thing, but with white on the third one.

让我解释一下:考虑下面这个图片:

Let me explain: consider this image below:

在Photoshop中,我有基层是那种颜色天蓝色的。我创建它的顶部两层,其中一个为黑色,一种白色的,但都具有50%的不透明度。现在,我可以使用颜色选择器(I)简单地选择两个想要的颜色。

In Photoshop, I have the base layer which is sort of sky blue in colour. I create two layers on top of it, one with black, one with white but both have an opacity of 50%. Now, I can use the colour picker (I) to simply select the two wanted colours.

我有这样做,我想知道如果我能编程产生它的时候,这一个疯狂的金额。

I am having to do this an insane amount of times so I was wondering if I could produce it programatically.

我知道,理想的情况是我已经尝试了一些东西,然后给了未使用的代码..但是这难倒我,以至于我甚至不知道从哪里开始。我见过的最接近的就是 的Kuler ,所以我认为这是可能的闪光至少,但话又说回来,我不知道从哪里开始。

I know, Ideally I should have tried out something, then give out the code which isn't working.. but this has stumped me enough that I don't even know where to start. The closest thing I've seen is Kuler so I think it is possible in flash at least, but then again, I don't know where to start.

你们可以请点我在正确的方向?理想情况下,这将是好多了,如果它在jQuery的可行的,但我环顾四周,但没有找到任何东西很喜欢它。 我不是要求一个有效的解决方案,只是在正确的方向轻推。

Can you guys please point me in the right direction? Ideally, this would be so much better if it's doable in jQuery, but I have looked around and couldn't find anything quite like it. I am not asking for a working solution, just a nudge in the right direction.

如果您有任何疑问,请询问。

If you have any questions, please ask.

技术对我来说并不重要,解决方案是 - 我最舒适的使用C#(至少我这样想我),但我是一个初学者在PHP中,闪光灯。 jQuery的,我擅长与大多数的东西(当然,谁不是呢?) - 无论工作原理是对我好。 <子>的PHP和Flash,我学会了它作为一种业余爱好只是为了了解我自己。

Technology is not important to me, solution is - I am most comfortable with c# (at least I like to think I am) but I am a beginner in php, flash. Jquery, I am good at it with most stuff (well, who isn't?) - Whatever works is good to me. Php and Flash, I learnt it as a hobby just to familiarize myself.

非常感谢。

推荐答案

所以我可以接近,但不完全是你的结果,我认为这是在范围 1使用了一些.NET的副作用..255 为阿尔法创建的颜色时。

So I can get close, but not exactly your results, which I think is a side effect of .NET using a number in the range 1..255 for alpha when creating a color.

但无论如何,我认为这几乎你想要做什么:

But nonetheless, I think this pretty much does what you want:

public class ColorUtility
{
    private Color color;

    public ColorUtility(Color original)
    {
        this.color = original;
    }

    public Color GetTransformedColor(Color overlay)
    {
        using(var bitmap = new Bitmap(1,1))
        {
            var g = Graphics.FromImage(bitmap);
            using(Brush baseBrush = new SolidBrush(this.color))
            {
                g.FillRectangle(baseBrush,0,0,1,1);
            }

            using(Brush overlayBrush = new SolidBrush(Color.FromArgb(127,overlay)))
            {
                g.FillRectangle(overlayBrush,0,0,1,1);
            }
            return bitmap.GetPixel(0, 0);
        }
    }
}



用法:

usage:

 var startColor = ColorTranslator.FromHtml("#359eff");
 var util = new ColorUtility(startColor);
 var blackOverlay = util.GetTransformedColor(Color.Black); // yields #9aceff
 var whiteOverlay = util.GetTransformedColor(Color.White); // yields #1b4f80



关闭到您想要的结果,但不完全。

Close to your desired results, but not exactly.

编辑:如果您更改Alpha值 128 在你得到的效用

If you change the alpha value to 128 in the utility you get

黑色:#9acfff结果
白色:#1a4f7f

Black: #9acfff
White: #1a4f7f

这可能是更接近于你想要什么,但它仍然不准确。

This might be closer to what you want, but its still not exact.

这篇关于采用黑色和白色混浊后产生的色彩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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