【问题标题】:Saving UserControl as image using WriteableBitmap not displaying text使用 WriteableBitmap 将 UserControl 保存为图像不显示文本
【发布时间】:2013-11-16 16:29:15
【问题描述】:

我有一个用户控件:

<UserControl x:Class="livetile.smalltile"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="159" d:DesignWidth="159">

    <Canvas x:Name="LayoutRoot" Background="Black" Width="159" Height="159">
        <TextBlock x:Name="day" Text="16" Width="159" TextAlignment="Center" FontSize="100" Foreground="White"/>
        <TextBlock x:Name="dayofweek" Text="Saturday" Width="159" TextAlignment="Center" Canvas.Top="100"FontSize="30" Margin="0,0,0,25" Foreground="White"/>
    </Canvas>
</UserControl>

然后我将其转换为 WriteableBitmap:

public WriteableBitmap GetBmp()
{
    this.Measure(new Size(159, 159));
    this.Arrange(new Rect(0, 0, 159, 159));

    // draw bmp
    var bmp = new WriteableBitmap(159, 159);
    bmp.Render(this, null);
    bmp.Invalidate();

    return bmp;
}

然后我使用这个 WriteableBitmap 来渲染 JPG 并保存它。问题是图像只显示画布的背景颜色,而不是其中的文本......我该如何解决这个问题?

【问题讨论】:

    标签: c# user-controls windows-phone writeablebitmap


    【解决方案1】:

    看起来这与我用于 TextBlocks 的自定义字体有关。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-12
      • 2012-03-26
      相关资源
      最近更新 更多