日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UWP 剪贴板 Clipboard

發布時間:2025/3/8 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UWP 剪贴板 Clipboard 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文: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

?

總結

以上是生活随笔為你收集整理的UWP 剪贴板 Clipboard的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。