I have news list, which contain thumbnails:

I'm getting JSON from server, which means pictures are - links
My code for inserting pictures:
foreach (Article article in NewsList.Result.Articles)
{
NewsListBoxItem NLBI = new NewsListBoxItem();
NLBI.Title.Text = article.Title;
NLBI.Date.Text = US.UnixDateToNormal(article.Date.ToString());
NLBI.id.Text = article.Id.ToString();
if (article.ImageURL != null)
{
BitmapImage image = new BitmapImage(new Uri(article.ImageURL));
NLBI.Thumbnail.Source = image;
}
NewsListBox.Items.Add(NLBI);
}
If i enter application in offline mode - they wont show up, so i need to save them, the most prefered method - as string!
Which means i need to convert them to Base64:
BitmapImage image = new BitmapImage(new Uri(article.ImageURL));
byte[] bytearray = null;
using (MemoryStream ms = new MemoryStream())
{
WriteableBitmap wbitmp = new WriteableBitmap(image );
wbitmp .SaveJpeg(ms, wbitmp.PixelWidth, wbitmp.PixelHeight, 0, 100);
ms.Seek(0, SeekOrigin.Begin);
bytearray = ms.GetBuffer();
}
string str = Convert.ToBase64String(bytearray);
Code fails with NullReferenceException where is my mistake?
Code fails on line:
WriteableBitmap wbitmp = new WriteableBitmap(image);
Error:
An exception of type 'System.NullReferenceException' occurred in System.Windows.ni.dll but was not handled in user code
I even tried to use this image from my project:
BitmapImage image = new BitmapImage(new Uri("Theme/MenuButton.png",UriKind.Relative));
But still fails with NullRef - but i know that image exists, if it was nul i wouldn't see it in ImageBox
BitmapImageobject. - Silvermind