Windows.Storage.Streams.InMemoryRandomAccessStream.ReadAsync C# (CSharp) Méthode

ReadAsync() public méthode

public ReadAsync ( [ buffer, [ count, [ options ) : uint>.IAsyncOperationWithProgress
buffer [
count [
options [
Résultat uint>.IAsyncOperationWithProgress
		public extern IAsyncOperationWithProgress<IBuffer, uint> ReadAsync([In] IBuffer buffer, [In] uint count, [In] InputStreamOptions options);
		public extern IAsyncOperationWithProgress<uint, uint> WriteAsync([In] IBuffer buffer);

Usage Example

        public static async Task<IBuffer> SaveAsPngIntoBufferAsync(this Canvas canvas, double _scaleFactor, int dpiForImage = 200)
        {
            //string currentresolution = Window.Current.Bounds.Width * scaleFactor + "*" + Window.Current.Bounds.Height * scaleFactor;
            RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
            await renderTargetBitmap.RenderAsync(canvas);
            var pixels = await renderTargetBitmap.GetPixelsAsync();
            using (IRandomAccessStream stream = new InMemoryRandomAccessStream())
            {
                var encoder = await
                    BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);

                byte[] bytes = pixels.ToArray();

                await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                         BitmapAlphaMode.Ignore,
                                         (uint)(canvas.ActualWidth * _scaleFactor), (uint)(canvas.ActualHeight * _scaleFactor),
                                         dpiForImage, dpiForImage, bytes);
                });

                await encoder.FlushAsync();
                stream.Seek(0);
                var buffer = WindowsRuntimeBuffer.Create((int)stream.Size);
                await stream.ReadAsync(buffer, (uint)stream.Size, InputStreamOptions.None);
                return buffer;
            }
        }
All Usage Examples Of Windows.Storage.Streams.InMemoryRandomAccessStream::ReadAsync