zoukankan      html  css  js  c++  java
  • 【UWP】截图

    完整代码如下:

    string desiredName =DateTime.Now.Ticks+".jpg";

                StorageFolder applicationFolder = ApplicationData.Current.LocalFolder;

                StorageFolder folder = await applicationFolder.CreateFolderAsync("Pic", CreationCollisionOption.OpenIfExists);

                StorageFile saveFile = await folder.CreateFileAsync(desiredName, CreationCollisionOption.OpenIfExists);

                RenderTargetBitmap bitmap = new RenderTargetBitmap();

                await bitmap.RenderAsync(PicGrid);

                var pixelBuffer =await bitmap.GetPixelsAsync();

                using(var fileStream=await saveFile.OpenAsync(FileAccessMode.ReadWrite))

                {

                    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);

                    encoder.SetPixelData(BitmapPixelFormat.Bgra8,

                        BitmapAlphaMode.Ignore,

                        (uint)bitmap.PixelWidth,

                        (uint) bitmap.PixelHeight,

                        DisplayInformation.GetForCurrentView().LogicalDpi,

                        DisplayInformation.GetForCurrentView().LogicalDpi,

                        pixelBuffer.ToArray());

                    await encoder.FlushAsync();

                }

                await new MessageDialog("保存成功").ShowAsync();




    链接:https://www.jianshu.com/p/939c8fd4d75b

  • 相关阅读:
    Java LinkedList 源码剖析
    Java并发编程:线程池的使用
    Java 线程池的原理与实现
    多线程JAVA篇(一)
    软件开发中会用到的图
    linux文件名匹配——通配符使用
    XModem协议
    dmesg 命令七种用法
    定位精度单位CEP、RMS、2DRMS常识
    5G NR 技术简介
  • 原文地址:https://www.cnblogs.com/MiLu/p/11058929.html
Copyright © 2011-2022 走看看