I'm trying to convert a .jpg or .png file to a writeable bitmap. I obtain the image in another source and convert to a base64 encoding. After removing the packaging, I have a width, height, and base64 data. I then use:
var base64 = dataurl.Substring(dataurl.IndexOf("base64,") + 7);
binData = Convert.FromBase64String(base64);
This gives me the binary data of my image. The problem really comes in that I'm writing this for windows phone 8, so I'm limited in what libraries and methods I can use. The obvious choice is:
using (var stream = new MemoryStream(binData, 0, binDta.Length, true, true))
{
var wbp = new WriteableBitmap(1,1).LoadJpeg(stream);
}
but I'm getting a System.ArgumentException from the WriteableBitmap library. Any ideas that work on Windows Phone 8?
You should make sure the base64 decoded data is really a valid format like JPG and PNG. Then I'd recommend you try the WriteableBitmapEx FromStream method: