0

The problem is here:

var allImages = commentXml.Elements("Image");
     if (allImages != null)
     {
         foreach (var image in allImages)
         {                            
             string base64string = GetElementValue(image.Element("Data"));
             MessageBox.Show(base64string);
             BitmapImage currentImage = await GetImageFromBase64String(base64string);
             MessageBox.Show(currentImage.PixelWidth.ToString());
             comment.Images.Add(currentImage);
         }
     }

The first MessageBox tells that base64string exists, the second MessageBox returns image width, but the last line throws NullReferenceException. Why this is going on? comment.Images object has ObservableCollection type.

Here's also GetImageFromBase64String function, but I'm think it's ok.

public async Task<BitmapImage> GetImageFromBase64String(string value)
    {
        if (value == null)
            return null;

        var buffer = System.Convert.FromBase64String(value);
        MemoryStream ms = new MemoryStream();
        DataWriter writer = new DataWriter(ms.AsOutputStream());
        writer.WriteBytes(buffer);
        await writer.StoreAsync();
        var image = new BitmapImage();
        image.SetSource(ms);
        return image;

    }
splash27
  • 2,057
  • 6
  • 26
  • 49

0 Answers0