Forum Xamarin.Forms

How to copy a picture file from device to an app's local folder?

ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭
edited March 2015 in Xamarin.Forms

I am using XLab's Camera control to select a picture from the device. The Camera Control gets me the ImageSource and I set myImage.Source to this. Fine. But now I want to copy this picture file to my app's local folder. How can I do that?

The Working with Files documentation shows me for only the Text Files, but not for any other file type.

Few questions that I have are:

  1. How to get the picture files full path+name from ImageSource, if at all possible?
  2. Can I use StreamReader and StreamWriter in Xamarin.Forms?
  3. Will use of System.IO.File.ReadAllBytes does fulfill my need?


  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    Bumping it...Any takers???

  • MacMcledMacMcled USMember


    We are having similar issue; I am reading about the PCLStorage package which might offer a solution to save the image to the required directory. I will update you if i get this to work.

    PCLStorage is used in the EmployeeDirectory sample listed under Xamarin.Forms.


  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    PCLStorage component can be used for only text files as it uses ReadAllText() method and so. That can't be used for .jpg or .png. It can read or write only .txt files.

    @MacMcled Sometime back you tried using StreamImagesourceHandler() in Android code. Can you tell me in which lib it is in? It is not in Xamarin.Forms or XLabs.Forms.Core.

  • MacMcledMacMcled USMember
    edited March 2015
    #region Assembly Xamarin.Forms.Platform.Android.dll, v1.3.3.0
    // .............................packages\Xamarin.Forms.\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll
    using Android.Content;
    using System;
    using System.Diagnostics;
    using System.Threading;
    using System.Threading.Tasks;
    using Xamarin.Forms;
    namespace Xamarin.Forms.Platform.Android
        public sealed class StreamImagesourceHandler : IImageSourceHandler, IRegisterable
            public StreamImagesourceHandler();
            public Task<Android.Graphics.Bitmap> LoadImageAsync(ImageSource imagesource, Context context, CancellationToken cancelationToken = null);
  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @MacMcled ThanQ...Your code for Android worked. Of course it appears I can't do it for WP as the Photo Hub folders are not revealed. Will try for iOS later. Of course, if someone has got a code snippet for iOS, all welcome.

Sign In or Register to comment.