我想在我的应用程序中保存我的文件夹名称照片中的图像。我使用FilePicker选择一个图像文件并在按钮上单击图像控件中显示我想将其保存在目录中。我该怎么做。我可以已经执行保存图片库但无法保存在文件夹中。任何人都可以提供示例代码吗?
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(MyCanvas);
//StorageFile saveFile = await KnownFolders.PicturesLibrary.GetFileAsync("sample.jpg");
StorageFolder storageFolder = KnownFolders.PicturesLibrary;
StorageFile sampleFile = await storageFolder.CreateFileAsync(name, CreationCollisionOption.ReplaceExisting);
var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();
using (var fileStream = await sampleFile.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);
encoder.SetPixelData(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Ignore,
(uint)renderTargetBitmap.PixelWidth,
(uint)renderTargetBitmap.PixelHeight,
DisplayInformation.GetForCurrentView().LogicalDpi,
DisplayInformation.GetForCurrentView().LogicalDpi,
pixelBuffer.ToArray());
await encoder.FlushAsync();