Clipboard使用Windows.ApplicationModel.DataTransfer.Clipboardhtml
設置文本dom
DataPackage dataPackage = new DataPackage(); dataPackage.SetText("文本"); Clipboard.SetContent(dp);
獲取文本ide
檢查剪貼板包含文本spa
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(); } }
獲取圖片.net
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(); } }
獲取文件code
if (con.Contains(StandardDataFormats.StorageItems)) { var filelist = await con.GetStorageItemsAsync(); foreach (StorageFile t in filelist) { } }
IStorageItem 轉 StorageFileorm
if (t.IsOfType(StorageItemTypes.File)) { StorageFile storageFile = storageItem as StorageFile; }
參考 https://blog.csdn.net/lindexi_gd/article/details/50479180htm