简体   繁体   English

着色器中使用的WPF Textblock的大小无法调整

[英]Size of WPF Textblock used in a shader cannot be resized

I have a shader that I want to apply to a WPF TextBlock. 我有一个要应用于WPF TextBlock的着色器。 However, my shader always seems to be limited to the texture that is equal to the bounding box of the text. 但是,我的着色器似乎总是局限于与文本的边框相同的纹理。 And, as result I cannot access pixels outside the bounding box (eg to add a large border or color effect). 而且,结果是我无法访问边界框之外的像素(例如,添加大边框或色彩效果)。 Everything I've tried to increase the bounding box, either in XAML or C#, before applying the shader has failed. 在应用着色器之前,我尝试增加XAML或C#中的边界框的所有操作均失败。

This picture shows the effect of applying a simple blue overlay shader to the text. 此图片显示了对文本应用简单的蓝色覆盖着色器的效果。 It shows the extents of the bounding box and the pixels that the shader has access to. 它显示了着色器可以访问的边界框的范围和像素。 So the question is really how to expand the text bounding box before calling the shader? 因此,问题实际上是在调用着色器之前如何扩展文本边界框? Hope someone has been through this problem before... 希望有人解决过这个问题...

I included the simply shader code below: 我在下面包括了简单的着色器代码:

sampler2D texSampler : register(S0);
float threshold : register (C0);
float4 txtColor : register (C1);

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float4 color = tex2D(texSampler, uv);

    color.r = txtColor[0];
    color.g = txtColor[1];
    color.b = txtColor[2];

    return color;
}

Sample text and bounding box 示例文本和边框

Here's what's going on - If a background is not specified for the TextBlock, then wpf puts a tight bounding box around the text regardless of the width and height specified for the TextBlock. 这是怎么回事-如果未为TextBlock指定背景,则wpf会在文本周围放置一个紧密的边框,而与为TextBlock指定的宽度和高度无关。 To fix the problem just set the Background color to Transparent for the TextBlock. 要解决此问题,只需将TextBlock的Background color设置为Transparent。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM