グロー効果は、適切なビジュアルに適用され、DrawText()呼び出しのような描画コンテキストメンバーには当てはまりません。あなたは
Visual theVisual = textBlock ; //Put the aimed visual here.
double width = Convert.ToDouble(theVisual.GetValue(FrameworkElement.WidthProperty));
double height = Convert.ToDouble(
theVisual.GetValue(FrameworkElement.HeightProperty));
if (double.IsNaN(width) || double.IsNaN(height))
{
throw new FormatException(
"You need to indicate the Width and Height values of the UIElement.");
}
RenderTargetBitmap render = new RenderTargetBitmap(
Convert.ToInt32(width),
Convert.ToInt32(this.GetValue(FrameworkElement.HeightProperty)),
96,
96,
PixelFormats.Pbgra32);
// Indicate which control to render in the image
render.Render(this);
Stream oStream = new MemoryStream();
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(render));
encoder.Save(oStream);
oStream.Flush();
(交互あなたにも描画コンテキストにそれを描くことができます)画像としてレンダリングするテキストブロックを使用し、その後
<TextBox Width="200">
<TextBox.BitmapEffect>
<!-- <BitmapEffectGroup> would go here if you wanted to apply more
then one effect to the TextBox. However, in this example only
one effect is being applied so BitmapEffectGroup does not need
to be included. -->
<!-- The OuterGlow is blue, extends out 30 pixels, has the
maximum noise possible, and is 40% Opaque. -->
<OuterGlowBitmapEffect GlowColor="Blue" GlowSize="30" Noise="1"
Opacity="0.4" />
</TextBox.BitmapEffect>
</TextBox>
...描画コンテキストに
TextBlock
のようなビジュアルを描くと考えることができます
これが役に立ったら教えてください....
これはうまくいっています(.NET 3.5)が、これを良いバックアップシナリオとして残しておきます。私はテキストボックスにdropshadoweffectと描画されたテキストにシミュレートされたドロップシャドウ効果を単純なシナリオに戻しました。二度。それは十分であり、.NET 4と互換性があります。 – mtijn