How to read image files using PCLStorage in Xamarin Forms on an Android?

Will.ItraxWill.Itrax CAMember ✭✭✭

Hi,
From within myApp I used XAM.Plugin.Media to take some pictures and store them in a new directory.
Using FileManager on the Android, I can navigate to the directory and open the pictures. It is something like:
Android/data/myApp.Droid/files/Pictures/myMobile/Project/SubName/

Using PCLStorage code from within myApp when I run:

IFolder rootFolder = FileSystem.Current.LocalStorage;

rootFolder has a path of: /data/data/myApp.Droid/files

Next I try to list all the folders that are one level below rootFolder by doing:

IList LF = await rootFolder.GetFoldersAsync();

it results in two folders:
/data/data/myApp.Droid/files/. __ override > __
/data/data/myApp.Droid/files/.config

I was expecting to get:
/data/data/myApp.Droid/files/Pictures

Any guidance on this topic is appreciated.

Best Answer

Answers

  • Will.ItraxWill.Itrax CAMember ✭✭✭

    A follow-up:
    I took another picture but this time used a blank for the Directory. The toast informed me that the picture was saved to:

    /Storage/emulated/0/Android/data/myApp.Droid/files/Pictures/myPic.jpg

    Using FileManager I found the picture where I expected to. I did not see the /Storage/emulated/0 part but the rest was as expected.

    Armed with that knowledge, I tried the following:

    IFile file = await FileSystem.Current.GetFileFromPathAsync ("/Storage/emulated/0/Android/data/myApp.Droid/files/Pictures/myPic.jpg");

    The debugger informed me that file is null and that:

    Method GetFileFromPathAsync not found in type `PCLStorage.IFileSystem'.

    That may explain why file is null, but if it is really true, how did it get past the compiler? What is going on here?

    Thanks for looking at this.

  • Will.ItraxWill.Itrax CAMember ✭✭✭

    Improvement (AFAIK):
    I have recently learned that XF can take a path to an image and display it. So now I bind to the path like this:
    Image Source="{Binding PhotoPath}"
    where PhotoPath is a string.

  • PrudhviRajuPrudhviRaju USMember

    @will

    Thanks Bro, You made my day......

  • MartinWunderlichMartinWunderlich USMember ✭✭
    edited December 2016

    das

Sign In or Register to comment.