1

I am stuck in my app. I have a grid with some elements in it. These elements are buttons, images and other controls like stackpanel and nested grids. I want to save what appears to the user as image on click of a button, but i dont know how to proceed on this.

Can I write elements like grid and buttons onto a writable bitmap? Or is there some other way?

In short I want to take a screen shot of my app screen when the user clicks the button. Please help.

Milan Aggarwal
  • 5,104
  • 3
  • 25
  • 54

4 Answers4

1

Unfortunately, it's not possible at this point. As @FilipSkakun mentions in a response here, you might be able to get part of the way depending on your requirements.

Community
  • 1
  • 1
Jim O'Neil
  • 23,344
  • 7
  • 42
  • 67
1

This has changed a bit in Windows 8.1 and can be accomplished using a RenderTargetBitmap. RenderTargetBitmap.RenderAsync(UIElement) will allow you to get the pixels for any element, including a page.

Here's an example that will save a PNG to a file specified using a FileSavePicker.

var filePicker = new FileSavePicker();
var file = await filePicker.PickSaveFileAsync();
var renderTargetBitmap = new RenderTargetBitmap();

using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
    await renderTargetBitmap.RenderAsync(this);
    var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();
    var pixelBytes = pixelBuffer.ToArray();

    encoder.SetPixelData(
        BitmapPixelFormat.Bgra8, 
        BitmapAlphaMode.Ignore, 
        (uint)renderTargetBitmap.PixelWidth, 
        (uint)renderTargetBitmap.PixelHeight, 
        96.0, 
        96.0, 
        pixelBytes);

    await encoder.FlushAsync();
}
Gabriel Isenberg
  • 25,869
  • 4
  • 37
  • 58
0

You can convert any UIElement into Jpeg image using the following option in Windows Phone 8.

var bitmap = new WriteableBitmap(element,null);

using (MemoryStream s = new MemoryStream())
{
     bitmap.SaveJpeg(s, (int)ContentPanel.Width, (int)ContentPanel.Height, 0, 100);
}

I hope it will be helpful to you.

David Bekham
  • 2,175
  • 3
  • 27
  • 56
0

Taking "screenshots" of winrt apps, or just controls is not possible on WinRt. Not implemented, and right now they don't plan on doing it.

Miiite
  • 1,517
  • 10
  • 16