似乎在Silverlight for
Windows Phone的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差别很大.有谁知道发生了什么事?