简体   繁体   中英

Copy and Save an image selected by the user in windows store apps using c#

I need to copy the image that user open and selects and save it and show the saved image to the user whenever an app reloads. help me show to save an image in Windows store app (not a web application).

Thanks in advance

You should use ApplicationDataContainer . Save the opened file to application settings, and on loading application get it and show. Example this

How does the user open and select the image? Using FileOpenPicker ? In this case just copy the StorageFile returned by it to the local storage and always retrieve it from there:

var picker = new FileOpenPicker();
picker.FileTypeFilter.Add(".jpg");
var file = await picker.PickSingleFileAsync();

var copiedFile = await file.CopyAsync(ApplicationData.Current.LocalFolder);

EDIT:

To display the image use the Image control. You can set the source to copied file directly in XAML using the ms-appdata scheme :

<Image x:Name="MyImage" Source="ms-appdata:///local/CopiedFile.jpg" />

Or you can set its source from code:

MyImage.Source = new BitmapImage(new Uri("ms-appdata:///local/CopiedFile.jpg"));

There are other ways of course, such as binding the Source property from view model), depending on what you're trying to achieve.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM