Clipboard使用Windows.ApplicationModel.DataTransfer.Clipboard

设置文本

DataPackage dataPackage = new DataPackage();
dataPackage.SetText("文本");
Clipboard.SetContent(dp);

获取文本

检查剪贴板包含文本

DataPackageView con = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();
if (con.Contains(StandardDataFormats.Text))
{ DataPackageView con = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();
string str = string.Empty;
if (con.Contains(StandardDataFormats.Text))
{
str = await con.GetTextAsync();
}
}

获取图片

if (con.Contains(StandardDataFormats.Bitmap))
{
RandomAccessStreamReference img = await con.GetBitmapAsync();
var imgstream = await img.OpenReadAsync();
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(imgstream); Windows.UI.Xaml.Media.Imaging.WriteableBitmap src = new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
src.SetSource(imgstream); Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(imgstream);
Windows.Graphics.Imaging.PixelDataProvider pxprd = await decoder.GetPixelDataAsync(Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, Windows.Graphics.Imaging.BitmapAlphaMode.Straight, new Windows.Graphics.Imaging.BitmapTransform(), Windows.Graphics.Imaging.ExifOrientationMode.RespectExifOrientation, Windows.Graphics.Imaging.ColorManagementMode.DoNotColorManage);
byte[] buffer = pxprd.DetachPixelData(); str = "image";
StorageFolder folder = await _folder.GetFolderAsync(str); StorageFile file = await folder.CreateFileAsync(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".png", CreationCollisionOption.GenerateUniqueName); using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateAsync(Windows.Graphics.Imaging.BitmapEncoder.PngEncoderId, fileStream);
encoder.SetPixelData(Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, Windows.Graphics.Imaging.BitmapAlphaMode.Straight, decoder.PixelWidth, decoder.PixelHeight, decoder.DpiX, decoder.DpiY, buffer);
await encoder.FlushAsync();
}
}

获取文件

            if (con.Contains(StandardDataFormats.StorageItems))
{
var filelist = await con.GetStorageItemsAsync();
foreach (StorageFile t in filelist)
{ }
}

IStorageItem 转 StorageFile

if (t.IsOfType(StorageItemTypes.File))
{
StorageFile storageFile = storageItem as StorageFile;
}

参考 https://blog.csdn.net/lindexi_gd/article/details/50479180

UWP 剪贴板 Clipboard的更多相关文章

  1. win10 UWP 剪贴板 Clipboard

    win10 UWP 剪贴板 Clipboard使用Windows.ApplicationModel.DataTransfer.Clipboard 设置文本 DataPackage dataPackag ...

  2. linux与windows共享剪贴板(clipboard)

    linux与windows共享剪贴板(clipboard)的方法 先说两句废话,其实linux和windows之间不需要共享剪贴板,直接在putty中,按住SHIFT+鼠标选择就可以了. 但是作为一种 ...

  3. Xamarin Essentials教程剪贴板Clipboard

    Xamarin Essentials教程剪贴板Clipboard   现在手机设备操作以触屏为主,不便于文本输入.虽然可以通过复制/粘贴的方式,借助系统剪贴板简化操作,但仍然不够方便.如果通过代码操作 ...

  4. c++builder Delphi 直接使用剪贴板 Clipboard

    c++builder Delphi 直接使用剪贴板 Clipboard 剪贴板 delphi use  Vcl.Clipbrd procedure TForm27.FormCreate(Sender: ...

  5. UWP 剪贴板

    一:剪贴板 一般的复制,用户自己光标选中文本,crtl +c复制就可以了.但是有时候也需求有一个复制的按钮,当用户点击复制按钮,就可以把当前的某些内容复制到剪贴板里. 这里就用到了DataPackag ...

  6. [React Native]访问操作系统剪贴板 Clipboard

    我们之前学习了TextInput组件, 有时候我们需要在TextInput组件中复制或者粘贴一些文字. React Native为开发者提供了 Clipboard API,Clipboard 组件可以 ...

  7. Salesforce LWC学习(二十八) 复制内容到系统剪贴板(clipboard)

    本篇参考: https://developer.mozilla.org/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipb ...

  8. html5: 复制到剪贴板 clipboard.js

    1.使用clipboard.min.js工具,引用此js 注意事项: IOS微信网页开发中,若使用此工具来开发复制功能,则需要在超链接/按钮上新增 onclick=" " 2.cl ...

  9. Js 之复制到剪贴板 clipboard.js

    一.下载 https://github.com/zenorocha/clipboard.js/archive/master.zip 二.Demo示例 <!DOCTYPE html> < ...

随机推荐

  1. 审计系统---堡垒机python下ssh的使用

    堡垒机python下ssh的使用 [堡垒机更多参考]http://www.cnblogs.com/alex3714/articles/5286889.html [paramiko的Demo实例]htt ...

  2. 重置 Winsock:初始化计算机网络环境

    初始化网络环境,以解决由于软件冲突.病毒原因造成的参数错误问题(复杂网络环境下慎用).批处理代码: netsh winhttp reset proxy netsh winhttp reset trac ...

  3. 详解权限管理(RBAC)的实现方法

    在说权限管理前,应该先知道权限管理要有哪些功能: ().用户只能访问,指定的控制器,指定的方法 ().用户可以存在于多个用户组里 ().用户组可以选择,指定的控制器,指定的方法 ().可以添加控制器和 ...

  4. SOAR平台初探(一)

    1.前言 Security Orchestration, Automation and Response(SOAR)安全编排和自动化响应,是Gartner2017年提出的新概念.Gartner预计到2 ...

  5. ZT Shell 排序

    Shell 排序 分类: 算法 C 2008-09-17 11:02 1898人阅读 评论(4) 收藏 举报 shell语言c 刚才在CSDN的C语言板块看到了有人说Shell排序的问题,所以一起学习 ...

  6. python subprocess 和 multiprocess选择以及我遇到的坑

    The subprocess option: subprocess is 用来执行其他的可执行程序的,即执行外部命令. 他是os.fork() 和 os.execve() 的封装. 他启动的进程不会把 ...

  7. nginx过一段时间出现400 Bad Request 错误的解决方法

    tomcat整合nginx成功后,等访问一段时间后,会出现 Bad Request (Invalid Hostname)的错误, 因为是已经成功的配置,所以判定可能是哪里的限制设置有问题,最后在官方网 ...

  8. 【转】Android 旋转动画,停止和持续旋转

    旋转180度后停止 RotateAnimation rotate; rotate =new RotateAnimation(0f,180f,Animation.RELATIVE_TO_SELF, 0. ...

  9. centos 系统安装基本步骤,面试必考

    1.调整开机媒体,通常为cd或者dvd,也可以是u盘. 2.选择安装模式,是否需要图形化 3.语系及键盘语系选择 4.软件选择 5.磁盘分区操作,主+扩展分区最多4个.逻辑分区在扩展分区下建立 6.时 ...

  10. leetcode589. N-ary Tree Preorder Traversal

    python 版: class Solution(object): def preorder(self, root): ret, q = [], root and [root] while q: no ...