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的编码处理(一)

    以下内容转载自: http://in355hz.iteye.com/blog/1860787 最近业务中需要用 Python 写一些脚本.尽管脚本的交互只是命令行 + 日志输出,但是为了让界面友好些, ...

  2. Data Compression

    数据压缩 introduction 压缩数据可以节省存储数据需要的空间和传输数据需要的时间,虽然摩尔定律说集成芯片上的晶体管每 18-24 个月翻一倍,帕金森定律说数据会自己拓展来填满可用空间,但数据 ...

  3. 面向对象程序设计_Task4_Calculator1.1

    The 2nd part of the Calculator program 题目链接:Click Here github链接:Click Here 诶嘿,第二部分,要开始实现计算的功能了,估计离不是 ...

  4. sql 模糊查询优化

    在sql语句中使用 like模糊查询时,应该尽量避免%%,因为模糊查询是比较慢的,当出现这样的情况时,应该考虑优化. 举个例子:我在表中查询2012 年创建的记录 SELECT * FROM `com ...

  5. 解决hibernate双向关系造成的一方重复执行SQl,或者死循环的问题

    系统采用struts-json hibernate3. 在对关联表配置manytoone onetomany双向关联的时候,在执行一方的时候,会发现打印出来的SQL语句多执行了一次或者多次.经过调试, ...

  6. java微信小程序解密AES/CBC/PKCS7Padding

    摘要:微信小程序解密建议使用1.6及以上的环境使用maven下载jar包org.bouncycastlebcprov-jdk15on1.55加密类代码importorg.bouncycastle.jc ...

  7. 常用的npm命令

    npm ls -g 列出全局安装的所有模块 npm ls webpack -g 查看全局安装的模块版本信息 npm view webpack versions 查看npm服务器上的全部版本信息 npm ...

  8. 【洛谷】【线段树】P1471 方差

    [题目背景:] 滚粗了的HansBug在收拾旧数学书,然而他发现了什么奇妙的东西. [题目描述:] 蒟蒻HansBug在一本数学书里面发现了一个神奇的数列,包含N个实数.他想算算这个数列的平均数和方差 ...

  9. 【转】彻底理解android中的内部存储与外部存储

    我们先来考虑这样一个问题: 打开手机设置,选择应用管理,选择任意一个App,然后你会看到两个按钮,一个是清除缓存,另一个是清除数据,那么当我们点击清除缓存的时候清除的是哪里的数据?当我们点击清除数据的 ...

  10. Test随笔

    测试一级主题 测试二级主题 测试内容,修改会不会出现历史记录