I need some help in convert image to base64string. I had used solution from similar question in stackoverflow but an error occured.
Solution used: convert image into base64 in wp8
The problem lies on the Image's Source I used to set as a writeablebitmap but the outcome was a null exception.
This is my image source :
image123.Source = new BitmapImage(new Uri("/correct1.jpg", UriKind.Relative));
Error occured in this line :
WriteableBitmap wbitmp = new WriteableBitmap((BitmapImage)image123.Source);
The Error:
An exception of type 'System.NullReferenceException' occurred in System.Windows.ni.dll but was not handled in user code
My existing code as reference :
image123.Source = new BitmapImage(new Uri("/correct1.jpg", UriKind.Relative));
byte[] bytearray = null;
using (MemoryStream ms = new MemoryStream())
{
if (image123.Source != null)
{
WriteableBitmap wbitmp = new WriteableBitmap((BitmapImage)image123.Source);
wbitmp.SaveJpeg(ms, 46, 38, 0, 100);
bytearray = ms.ToArray();
}
}
str = Convert.ToBase64String(bytearray);
binarytxt.Text = str;
I'm really desperate for help as this is my major project. Thanks in advance!