2017-04-14 3 views
0

J'ai fait beaucoup de R & D sur Google que comment puis-je enregistrer une zone spécifique de ma vue en tant qu'image dans Universal Windows Store Application. Nous pouvons le faire facilement dans WPF. Mais Bitmap et certaines bibliothèques ne font pas partie d'Universal Platform.Comment enregistrer une zone spécifique de vue sous forme d'image dans UWP?

J'ai également essayé cette bibliothèque mais je n'y suis pas parvenu. https://github.com/teichgraf/WriteableBitmapEx

Répondre

1

Jetez un oeil à cette classe: RenderTargetBitmap dans l'espace de noms Windows.UI.Xaml.Media.Imaging. Il expose la méthode suivante.

public IAsyncAction RenderAsync(UIElement element, Int32 scaledWidth, Int32 scaledHeight) 

Voici un Snipped pour convertir un UIElement à SoftwareBitmap

RenderTargetBitmap renderTarget = new RenderTargetBitmap(); 
await renderTarget.RenderAsync(uiElement); 

IBuffer pixelBuffer = await renderTarget.GetPixelsAsync(); 
SoftwareBitmap bitmap = SoftwareBitmap.CreateCopyFromBuffer(pixelBuffer, BitmapPixelFormat.Bgra8, (int) uiElement.RenderSize.Width, (int) uiElement.RenderSize.Height, BitmapAlphaMode.Premultiplied); 

Vous pouvez alors lire cette page d'aide: Create, Edit and Save bitmap images pour plus d'informations sur l'utilisation SoftwareBitmap.