Domanda

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.

È stato utile?

Soluzione 3

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.

Altri suggerimenti

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.

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();
}

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top