似乎在适用于 Windows Phone 的 Silverlight 的 WriteableBitmap 中有一个非常烦人的错误。我有以下代码和 xaml:
public partial class MainPage : PhoneApplicationPage
{
CompositeTransform rotate = new CompositeTransform();
public MainPage()
{
InitializeComponent();
}
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
this.rotate.Rotation += 15;
WriteableBitmap bmp = new WriteableBitmap(this.button, rotate);
this.image.Source = bmp;
Dispatcher.BeginInvoke(() => Debug.WriteLine("{0}, {1}", bmp.PixelWidth, bmp.PixelHeight));
}
}
这是xaml:
<Grid>
<Button VerticalAlignment="Top"
HorizontalAlignment="Center"
Content="This is a textblock inside a layout"
x:Name="button"/>
<Image VerticalAlignment="Center"
HorizontalAlignment="Center"
x:Name="image"/>
<Button VerticalAlignment="Bottom"
Content="Rotate"
Click="Button_Click"/>
</Grid>
当您单击底部按钮时,顶部按钮将使用复合变换与可写位图一起呈现。每次渲染后,顶部按钮的结果图像都比前一个大。此外,可写位图的 PixelWith 和 PixelHeight 属性值与 Image 对象的 RenderSize 大不相同。有谁知道发生了什么?