简体   繁体   English

如何将图像从Filepiker复制到应用程序文件夹Windows存储应用程序

[英]how to copy image from filepiker to app folder windows store apps

this is the code of file picker 这是文件选择器的代码
i need to copy the image that user open it to app folder. 我需要将用户打开的图像复制到应用程序文件夹中。 any one can help me please 任何人都可以帮助我

private async void Button_Click(object sender, RoutedEventArgs e)
    {

        if (Windows.UI.ViewManagement.ApplicationView.Value != Windows.UI.ViewManagement.ApplicationViewState.Snapped ||
             Windows.UI.ViewManagement.ApplicationView.TryUnsnap() == true)
        {
            Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
            openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

            // Filter to include a sample subset of file types.
            openPicker.FileTypeFilter.Clear();
            openPicker.FileTypeFilter.Add(".bmp");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".jpg");

// Open the file picker. //打开文件选择器。

        Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync();

            // file is null if user cancels the file picker.
            if (file != null)
            {
                // Open a stream for the selected file.
                Windows.Storage.Streams.IRandomAccessStream fileStream =
                    await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

// Set the image source to the selected bitmap.` //将图像源设置为选定的位图。

                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                    new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                bitmapImage.SetSource(fileStream);
                img.Source = bitmapImage;
                this.DataContext = file;


            }
        }

    }

thanks 谢谢

Use StorageFile.CopyAsync , that is, file.CopyAsync. 使用StorageFile.CopyAsync ,即file.CopyAsync。 The first argument is the destination StorageFolder, eg Windows.Storage.ApplicationData.Current.LocalFolder if you wanted to copy to appdata; 第一个参数是目标StorageFolder,例如Windows.Storage.ApplicationData.Current.LocalFolder(如果要复制到appdata); otherwise you'd need to create a folder or get one from a picker separately. 否则,您需要创建一个文件夹或从选择器中单独获取一个。

You might, for example, have the user choose a default folder with the file picker (configured for folders). 例如,您可以让用户使用文件选择器(为文件夹配置)选择默认文件夹。 Just be sure to save that StorageFolder in the [Windows.Storage.AccessCache][2] to preserve programmatic access for future use. 只需确保将StorageFolder保存在[Windows.Storage.AccessCache][2]以保留编程访问权限以备将来使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将从url(服务器)下载的图像保存到Windows应用商店中的本地文件夹 - how to save image downloaded from url(server) to local folder in windows store app 如何在Windows应用商店应用中将图像压缩到70%? - How to compress the image to 70% in the Windows Store apps? 如何通过UWP应用将文件选择器中的图像复制到anotehr文件夹中? - how to copy an image from the filepicker into anotehr folder via an UWP app? 从Windows应用商店应用访问本地文件夹? - access local folder from Windows Store app? 放大Windows应用商店应用中的图像 - Zooming into image in Windows Store apps 如何将从Kinect v2保留的WriteableBitmap对象保存到Windows Store应用程序中的图像文件 - How to save a WriteableBitmap obejct retained from Kinect v2 to an image file in Windows Store apps 从Windows应用商店访问Windows Phone文件夹 - Access Windows Phone folder from Windows Store app 如何使用Windows Store应用程序编程从Windows 8中的特定文件夹中获取文件? - how to get files from particular folder in windows 8 using windows store app programming? 从Windows Store应用清除图像 - Clear image from windows store app 使用c#复制并保存用户在Windows应用商店中选择的图像 - Copy and Save an image selected by the user in windows store apps using c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM