locked
[UWP]How can i update an image from the Assets folder ? RRS feed

  • Question

  • In a Windows Universal Windows app, how can i update an image from the Assets folder ?

     <Imagex:Name="ArrowImage"HorizontalAlignment="Left"Height="28"Margin="109,10,0,0"VerticalAlignment="Top"Width="100"Source="{BindingImageUpDown}"/>

    Thanks in advance ;)


    • Edited by Barry Wang Monday, October 19, 2015 2:27 AM Edit Title
    Friday, October 16, 2015 8:41 AM

Answers

  • Hello Tabsman,

    The Assets folder after you deployed your app is in the installed location. If you want to update the Assets folder at run time, it is not supported since the installed location is read only. So if you want to change the image, you can only change the image in assets folder at design time.

    To make the image update at runtime, please change your images stored location. For example, put them in the PicturesLibrary | picturesLibrary property And then you can read/write your image to it.

    For the image API, we need to check this Imaging

    Best regards,

    Barry

     


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Nasarudin Harun Saturday, October 24, 2015 4:03 AM
    • Marked as answer by Barry Wang Thursday, October 29, 2015 1:21 AM
    Monday, October 19, 2015 2:44 AM
  • Hi Jean,

      I'm not too sure if you meant by changing images whenever the user press your image? Well what you can do is adding a tap event to your image like the following.

    <Imagex:Name="ArrowImage"HorizontalAlignment="Left"Height="28"Margin="109,10,0,0"VerticalAlignment="Top"Width="100"Source="ms-appx:///Assets/up.png" Tapped="ArrowImage_Tapped"/>

    Then behind your code you can add the following :-

    //add this first
    using Windows.UI.Xaml.Media.Imaging;
    
    // Declare your current pointer if it's up or down.
    bool up = false;
    
    private void ArrowImage_Tapped(object sender, TappedRoutedEventArgs e)
            {
               if (up == false)
    {
    //set your flag to true to determine that the arrow is up
    bool = true;
    
    // By changing the source, this will make your arrow go up.
    ArrowImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/up.png"));
    }
    else
    {
    //set your flag to which will state that the arrow is not pointing up
    bool = false;
    
    // By changing the source, this will make your arrow go down.
    ArrowImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/down.png"));
    }
    }
    Hope this answers your question.


    • Edited by Osirus Saturday, October 24, 2015 4:16 AM
    • Marked as answer by Tabsman Saturday, October 31, 2015 3:42 PM
    Saturday, October 24, 2015 4:14 AM

All replies

  • Hello Tabsman,

    The Assets folder after you deployed your app is in the installed location. If you want to update the Assets folder at run time, it is not supported since the installed location is read only. So if you want to change the image, you can only change the image in assets folder at design time.

    To make the image update at runtime, please change your images stored location. For example, put them in the PicturesLibrary | picturesLibrary property And then you can read/write your image to it.

    For the image API, we need to check this Imaging

    Best regards,

    Barry

     


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Nasarudin Harun Saturday, October 24, 2015 4:03 AM
    • Marked as answer by Barry Wang Thursday, October 29, 2015 1:21 AM
    Monday, October 19, 2015 2:44 AM
  • Thanks for the answhere.

    But I want to give an image box in the run time a different image from the Assets folder. That must go?

    Jean

     
    Friday, October 23, 2015 8:07 PM
  • Hi Jean,

      I'm not too sure if you meant by changing images whenever the user press your image? Well what you can do is adding a tap event to your image like the following.

    <Imagex:Name="ArrowImage"HorizontalAlignment="Left"Height="28"Margin="109,10,0,0"VerticalAlignment="Top"Width="100"Source="ms-appx:///Assets/up.png" Tapped="ArrowImage_Tapped"/>

    Then behind your code you can add the following :-

    //add this first
    using Windows.UI.Xaml.Media.Imaging;
    
    // Declare your current pointer if it's up or down.
    bool up = false;
    
    private void ArrowImage_Tapped(object sender, TappedRoutedEventArgs e)
            {
               if (up == false)
    {
    //set your flag to true to determine that the arrow is up
    bool = true;
    
    // By changing the source, this will make your arrow go up.
    ArrowImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/up.png"));
    }
    else
    {
    //set your flag to which will state that the arrow is not pointing up
    bool = false;
    
    // By changing the source, this will make your arrow go down.
    ArrowImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/down.png"));
    }
    }
    Hope this answers your question.


    • Edited by Osirus Saturday, October 24, 2015 4:16 AM
    • Marked as answer by Tabsman Saturday, October 31, 2015 3:42 PM
    Saturday, October 24, 2015 4:14 AM
  • @Jean,

    In that way you have to change your imagebox's source folder from asserts to other folders. In that way you will be able to use those images(read and write) at runtime.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Barry Wang Monday, October 26, 2015 1:48 AM
    • Proposed as answer by Barry Wang Wednesday, October 28, 2015 10:11 AM
    Monday, October 26, 2015 1:19 AM
  • So easy? Unbelievable !

    And it works !

    Thank you :)

    Saturday, October 31, 2015 3:37 PM
  • It works with the following code from Barry Wang:

    ArrowImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/up.png"));

    Thanks ;)

    Saturday, October 31, 2015 3:42 PM
  • It works with the following code from Barry Wang:

    ArrowImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/up.png"));

    Thanks ;)

    Glad to know it worked for you..  All the best and happy coding :)
    Saturday, October 31, 2015 4:14 PM