0

我正在使用 WPFMediakit 和两个单色相机,我想更改这些控件的色调。是否可以单独对 wpf 控件进行色调处理?

4

1 回答 1

1

A simple method that you can use on grayscale images is to put a semi-transparent rectangle above the control you want to tint. This method has limitations which the method below doesn't.

e.g to tint blue

<Grid>
    <Image Source="C:\Windows\Web\Wallpaper\img1.jpg" />
    <Rectangle Fill="#86004EFF" />
</Grid>

As gray has no saturation changing the hue of a grayscale image won't do anything, a hue shift like this one wouldn't help you. You could however adjust that effect so it behaves like the colourize feature in Photoshop like this:

/// <summary>Hue</summary>
/// <minValue>0</minValue>
/// <maxValue>1</maxValue>
/// <defaultValue>0</defaultValue>
float Hue : register(c0);

/// <summary>Saturation</summary>
/// <minValue>0</minValue>
/// <maxValue>1</maxValue>
/// <defaultValue>0</defaultValue>
float Saturation : register(c1);

sampler2D Samp : register(S0);
float3 hsv_to_rgb(float3 HSV)
{
    float3 RGB = HSV.z;
    float var_h = HSV.x * 6;
    float var_i = floor(var_h);   // Or ... var_i = floor( var_h )
    float var_1 = HSV.z * (1.0 - HSV.y);
    float var_2 = HSV.z * (1.0 - HSV.y * (var_h-var_i));
    float var_3 = HSV.z * (1.0 - HSV.y * (1-(var_h-var_i)));
    if      (var_i == 0) { RGB = float3(HSV.z, var_3, var_1); }
    else if (var_i == 1) { RGB = float3(var_2, HSV.z, var_1); }
    else if (var_i == 2) { RGB = float3(var_1, HSV.z, var_3); }
    else if (var_i == 3) { RGB = float3(var_1, var_2, HSV.z); }
    else if (var_i == 4) { RGB = float3(var_3, var_1, HSV.z); }
    else                 { RGB = float3(HSV.z, var_1, var_2); }
   return (RGB);
}

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float4 col = tex2D(Samp, uv);
    float gray = col.r*0.3 + col.g*0.59 + col.b * 0.11;
    return float4(hsv_to_rgb(float3(Hue,Saturation,gray)),col.w);
}

Check out Shazzam for working with custom effects.

于 2011-07-28T21:39:31.700 回答