PCL Save Image File to local File System

14,637

Solution 1

How about something like this:

IFile file = await FileSystem.Current.GetFileFromPathAsync(fs.filepath);
byte[] buffer = new byte[100];
using (System.IO.Stream stream = await file.OpenAsync(FileAccess.ReadAndWrite))
{
    stream.Write(buffer, 0, 100);
}

Edit: Some code taken from http://pclstorage.codeplex.com/

IFile file = await folder.CreateFileAsync("myfile.abc", CreationCollisionOption.ReplaceExisting);

Once you've got the IFile object you should then be able to use this in the same way:

IFile file = await folder.CreateFileAsync("myfile.abc", CreationCollisionOption.ReplaceExisting);
byte[] buffer = new byte[100];
using (System.IO.Stream stream = await file.OpenAsync(FileAccess.ReadAndWrite))
{
    stream.Write(buffer, 0, 100);
}

Solution 2

You can also check out Paul Betts ' Splat library for cross platform image loading/saving.

https://github.com/paulcbetts/splat

Share:
14,637
flo1411
Author by

flo1411

Updated on July 22, 2022

Comments

  • flo1411
    flo1411 almost 2 years

    I am looking for a way to store image files in my local filesystem using the PCL Storage plugin in my core Project for Windows Phone, Xamarin.Android and Xamarin.iOS. However, the plugin does just provide methods for writing Text. Nothing about bytes. Is there a way to save byte arrays?