Reputation: 87
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
Upvotes: 0
Views: 764
Reputation: 17855
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.
Upvotes: 1
Reputation: 897
You should use ApplicationDataContainer
. Save the opened file to application settings, and on loading application get it and show. Example this
Upvotes: 1