UWP 剪贴板 Clipboard

简介: 原文:UWP 剪贴板 ClipboardClipboard使用Windows.ApplicationModel.DataTransfer.Clipboard   设置文本   DataPackage dataPackage = new DataPackage(); dataPackage.
原文: UWP 剪贴板 Clipboard

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

 

目录
相关文章
|
SQL Java 数据库连接
mybatis 中的 updateByPrimaryKey 与 updateByPrimaryKeySelective 的原理与区别实战详解
mybatis 中的 updateByPrimaryKey 与 updateByPrimaryKeySelective 的原理与区别实战详解
655 0
mybatis 中的 updateByPrimaryKey 与 updateByPrimaryKeySelective 的原理与区别实战详解
|
调度 知识图谱
【综合能源】含氢气氨气综合能源系统优化调度【免费】
该程序参考《_基于氨储能技术的电转氨耦合风–光–火综合能源系统双层优化调度》模型,对制氨工厂、风力发电、电制氢、燃气轮机、火电机组等主体进行建模分析,以火电机组启停成本、煤耗成本、弃风成本和购气成本形成的综合成本为目标,程序采用matlab+cplex求解,注释清晰,方便学习!
|
存储 安全 Linux
|
4月前
|
消息中间件 数据库 UED
1.1 同步调用与异步调用
本文介绍了微服务间的同步与异步调用。同步调用需等待结果返回,顺序执行,适合实时性高、操作简单的场景;异步调用发出请求后可继续执行其他任务,提升效率与资源利用率,适用于耗时操作。通过支付、点餐、挂号等生活实例对比,阐述了二者特点、适用场景及优缺点。
|
运维 监控 供应链
《统计学简易速速上手小册》第7章:时间序列分析(2024 最新版)
《统计学简易速速上手小册》第7章:时间序列分析(2024 最新版)
263 1
|
存储 算法
【操作系统】虚拟存储管理-页面置换算法
【操作系统】虚拟存储管理-页面置换算法
1227 0
|
5月前
|
Java 数据库 微服务
Java 学习路线可按「基础→进阶→实战→架构」四阶段推进
Java学习路线分四阶段:基础→进阶→实战→架构。涵盖语法、多线程、框架、微服务等核心内容,搭配项目实战与学习技巧,助你系统掌握Java开发技能,逐步成长为高级工程师。(238字)
584 4
|
机器学习/深度学习 自然语言处理
深度剖析Transformer核心思想 "Attention Is All You Need"
深度剖析Transformer核心思想 "Attention Is All You Need"
|
资源调度 前端开发 JavaScript
原子化 CSS 实践
本文介绍了 原子化 CSS 的相关背景概念、UnoCSS 的特点、用法。通过阅读本文,你可以了解如何使用 这款 CSS 引擎。
684 0
原子化 CSS 实践
|
8月前
|
JSON 监控 API
京东 API 助力,京东平台促销活动效果实时评估
在电商竞争激烈的背景下,京东平台促销活动成为商家提升销量的重要手段。传统评估方式滞后,难以及时调整策略。京东开放平台提供的API可实现实时数据获取与分析,助力商家高效评估活动效果。通过API,商家能实时追踪流量、监控销售数据、分析转化率与平均订单价值,快速响应市场变化。结合Python代码示例,本文详解如何调用京东API进行数据处理与指标计算,实现自动化监控与策略优化。实际案例显示,使用京东API后,某品牌活动响应时间缩短至秒级,销售额提升20%。京东API推动了从“事后复盘”到“实时优化”的转变,助力商家提升ROI,增强竞争力。
353 0