保存图像表单剪贴板 [英] Saving image form Clipboard
本文介绍了保存图像表单剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将winrt中的一个Image保存到文件夹中。但我发现没有办法。你可以帮忙吗?
i want to save one Image inside clipboard in winrt to file. but i found no way. can you help please?
var dataPackage = Clipboard.GetContent();
var t = await dataPackage.GetBitmapAsync();
var t2 = await t.OpenReadAsync();
t2.AsStream();
t2.Seek(0);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(t2);
Image image = new Image();
image.Source = bitmapImage;<
推荐答案
在这里:)
请注意,您无法使用任何文件夹进行保存。我已经将 ApplicationData.Current.LocalFolder.Path
作为desination传递。您可以使用 FolderPicker
然后传递拾取文件夹的路径。
Please note you can't use ANY folder to save. I have passed ApplicationData.Current.LocalFolder.Path
as desination. You can use FolderPicker
and then pass the path of picked folder.
private async Task StoreImageFromClipboardAsync()
{
var dataPackage = Clipboard.GetContent();
var formats = dataPackage.AvailableFormats;
if (formats.Contains("Bitmap"))
{
var t = await dataPackage.GetBitmapAsync();
var file = await ChangeIRASRToStorageFileAsync(t, ApplicationData.Current.LocalFolder.Path, "Clipboard.png");
}
}
private async Task<StorageFile> ChangeIRASRToStorageFileAsync(IRandomAccessStreamReference MyIRASR, String StorageFolderPath, String StorageFileName)
{
IRandomAccessStreamWithContentType MyIRASWCT = await MyIRASR.OpenReadAsync();
StorageFolder MyStorageFolder = await StorageFolder.GetFolderFromPathAsync(StorageFolderPath);
StorageFile MyStorageFile = await MyStorageFolder.CreateFileAsync(StorageFileName, CreationCollisionOption.ReplaceExisting);
Windows.Storage.Streams.Buffer MyBuffer = new Windows.Storage.Streams.Buffer(Convert.ToUInt32(MyIRASWCT.Size));
IBuffer iBuf = await MyIRASWCT.ReadAsync(MyBuffer, MyBuffer.Capacity, InputStreamOptions.None);
await FileIO.WriteBufferAsync(MyStorageFile, iBuf);
return MyStorageFile;
}
这篇关于保存图像表单剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文