it seems that there is a really annoying bug in WriteableBitmap for Silverlight for Windows Phone. I have the following code and 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));
}
}
Here is the 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>
When you click the bottom button, the top button is rendered with the writeable bitmap using the composite transform. After every render, the resulting image of the top button is larger than the previous one. Also, the PixelWith and PixelHeight property values of the writeable bitmap differ wildly from the RenderSize of the Image object. Does anyone have any idea what is going on?