Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PCL Save Image File to local File System

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?

like image 374
flo1411 Avatar asked Mar 19 '14 07:03

flo1411


1 Answers

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);
}
like image 173
Dave Avatar answered Oct 01 '22 23:10

Dave