BitmapFactory.DecodeFile Getting null

AMNishanthiKumariAMNishanthiKumari USMember ✭✭✭
edited April 30 in Xamarin.Android

I need to get a image from device local path(/storage/emulated/0/Android/data/android.mobille/logo.png) . I tried this code. But its return null. I gave Read external storage and write external storage permissions also.

string path = CommonOperations.GetLocalTargetPath("log.png");
Bitmap bitmap = BitmapFactory.DecodeFile(path);
var splashImageView = FindViewById<ImageView>(Resource.Id.splash);
splashImageView.SetImageBitmap(bitmap);

Tagged:

Best Answer

  • AMNishanthiKumariAMNishanthiKumari US ✭✭✭
    edited April 30 Accepted Answer

    I found the issue. my file path is missing file folder.

    /storage/emulated/0/Android/data/android.mobille/logo.png)

    after 'android.mobille/' this part need to add file/logo.png

    So full path should be /storage/emulated/0/Android/data/android.mobille/file/logo.png

    i have to hardcode that part to get this one.

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited April 30

    @AMNishanthiKumari
    Hi, did you misuse 'log.png' as 'logo.png'? See the picture

  • AMNishanthiKumariAMNishanthiKumari USMember ✭✭✭

    @yelinzh Thanks. i have correct it and tried but same issue is there. always return null value for following code.

    Bitmap bitmap = BitmapFactory.DecodeFile(path);

  • AMNishanthiKumariAMNishanthiKumari USMember ✭✭✭
    edited April 30 Accepted Answer

    I found the issue. my file path is missing file folder.

    /storage/emulated/0/Android/data/android.mobille/logo.png)

    after 'android.mobille/' this part need to add file/logo.png

    So full path should be /storage/emulated/0/Android/data/android.mobille/file/logo.png

    i have to hardcode that part to get this one.

  • DimChrisDimChris USMember ✭✭✭

    Marked it as answer

Sign In or Register to comment.