Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Winrt c# copy image from asset to localstorage

I come to you today because i don't know how to copy an image from asset to localstorage. I try a something like :

StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(
    new Uri("appx:///Assets/image.png"));

await file.CopyAsync(ApplicationData.Current.LocalFolder, "image.png");

But it doesn't work at all. Does anyone have an idea to do this right ? Thanks for your time, Regards.

like image 910
Sw1a Avatar asked Dec 21 '22 08:12

Sw1a


2 Answers

Your Uri scheme is invalid. It should be ms-appx:, not appx::

StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(
    new Uri("ms-appx:///Assets/image.png"));

await file.CopyAsync(ApplicationData.Current.LocalFolder, "image.png");

See this post for valid Uri schemes: URI schemes supported in Windows 8 apps

like image 185
chue x Avatar answered Jan 08 '23 03:01

chue x


Refer this link

Download an image to local storage in Metro style apps

Also

How ro store image locally once it was downloaded by Image control in Windows 8?

Might be helpful.

like image 36
Freelancer Avatar answered Jan 08 '23 04:01

Freelancer