Forum Xamarin.Android

How to replace an image?

Hello there

I am trying to figure out how to replace an image that is set by default. e.g I have a wallpaper set as default when I start my application.
What I am trying to get i, if I copy a new png on the Download folder.

This new image will replace the "old" wallpaper.

Would you mind to help me?
Thanks in advance.

Best Answer

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    Accepted Answer

    This issue is related to android? Is it related to the UWP? I notfice your screenshot, This NewWallpaper in the PC not in android device or android emulator.

    Could your give me more information about it?
    I found a thread about change an image source based on conditions, you can refer to it.

    https://social.msdn.microsoft.com/Forums/en-US/a8b7b16c-a6da-45da-869a-a6c9ba7a02ed/uwp-how-do-i-change-an-image-source-based-on-conditions-in-the-c?forum=WindowsIoT

  • NotCoconutNotCoconut Member ✭✭

    @LeonLu is related to android, I connected the my phone (samsung s7) on the pc and the screenshot is from the android path where I pasted the wallpaper.

    The main idea is to put differents wallpapers in a android folder, and everytime that I change the file the wallpaper should change too.

    Thanks!

  • NotCoconutNotCoconut Member ✭✭

    @LeonLu I find out a solution!

    public static string GetNewImg(string pImgName)
    {
    IFileSystemOperationsService fileService = DependencyService.Get();
    string fullPath = String.Empty;
    string lsResul = String.Empty;
    try
    {
    string imgpath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DataDirectory.Name).AbsolutePath;
    fullPath = imgpath + pImgName;
    }
    catch (Exception e)
    {
    }
    return lsresul;
    }

    And on every OnAppearing I do this:

    if (!(GetNewImg("BackGround1.jpg") == String.Empty))
    {

                BackGroudname.Source = GetNewImg("BackGround1.jpg");
    
            }
    
Sign In or Register to comment.