弹来弹去跑马灯!

uwp 保存UI图片

private async  void Button2_Click(object sender, RoutedEventArgs e)
        {
            var bitmap = new RenderTargetBitmap();
            StorageFile file = await KnownFolders.PicturesLibrary.CreateFileAsync("1.jpg", CreationCollisionOption.GenerateUniqueName);//需要设包访问本地图片库的读写权限
            await bitmap.RenderAsync(grid);
            var buffer = await bitmap.GetPixelsAsync();
            using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                var encod = await BitmapEncoder.CreateAsync(  BitmapEncoder.JpegEncoderId, stream);
                encod.SetPixelData(BitmapPixelFormat.Bgra8,
                    BitmapAlphaMode.Ignore,
                    (uint)bitmap.PixelWidth,
                    (uint)bitmap.PixelHeight,
                    DisplayInformation.GetForCurrentView().LogicalDpi,
                    DisplayInformation.GetForCurrentView().LogicalDpi,
                    buffer.ToArray()
                   );
                await encod.FlushAsync();
            }
            new MessageDialog("ss" + grid.Children.Count ).ShowAsync();
        }

 

可惜在有的机器上测试 截图是黑色的一片。。。。。。。。。。。。。。。。。。。 

 

 

 

 

 

posted @ 2017-10-18 17:37  wgscd  阅读(142)  评论(0)    收藏  举报