Reputation: 1157
Is it possible to get a bitmap of a specific control in Windows Phone?
In WindowsForm applications this is possible with the DrawToBitmap method, but in Windows Phone there isn't a method like that.
What shall I do?
Upvotes: 0
Views: 493
Reputation: 39007
It is possible, using the WriteableBitmap
class.
Let's say you have two controls, a button and an image:
<StackPanel>
<Button x:Name="Button1" Content="Test" Click="Button1_Click" />
<Image x:Name="Image1" />
</StackPanel>
And you want to generate a bitmap from the button, and assign it to Image1
. Then just use the constructor of the WriteableBitmap that expects a UIElement, and assign your bitmap to the image control:
private void Button1_Click(object sender, RoutedEventArgs e)
{
// Creates a bitmap with a visual representation of the button
var bitmap = new WriteableBitmap(this.Button1, null);
// Assigns the bitmap to the image control
this.Image1.Source = bitmap;
}
Upvotes: 2