Bitmap images Binding

Total Post:134

Points:940
WPF 
WPF
 1853  View(s)
Ratings:
Rate this:

What is the problem in this code ? Why the firstimage did not show on XAML page when I am binding the source of image in XAML to firstimage here in the code? The class contains the code is not a partial class.

if (ImagesAsSource[realty.ObjectId].Count == 0)
//private static Uri _baseUri = new Uri("ms-appx:///");
{
    Uri img = new Uri(_baseUri, "Assets/back.jpg");
    BitmapImage result = new BitmapImage();
    result.UriSource = img;
    // firstimage  is type of ImageSoure
    firstimage  =result;
}
//I tried this:
//private static Uri _baseUri = new Uri("ms-appx:///");
{
    Uri img = new Uri(_baseUri, "Assets/back.jpg");
    BitmapImage result = new BitmapImage(img );
    // firstimage  is type of ImageSoure
    firstimage  =result;
}
  1. Post:145

    Points:1019
    Re: Bitmap images Binding

    Hi Tanuj,

    You should try something like this:

    Uri img = new Uri(_baseUri, "Assets/back.jpg");
    var webClient = new WebClient();
    byte[] imageBytes = webClient.DownloadData(img);
    BitmapImage result = new BitmapImage(imageBytes);

    In fact I don't know constructor for your BitmapImage, so may be you should convert byte[] into Stream

      Modified On Apr-04-2018 12:14:37 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!