I'm trying to convert base64 string to image and bind the result.
This is my xaml :
<Image Source="{Binding image64}">
To be sure my base64 string is correct i did that :
public BitmapImage image64
{
get
{
**//Convert my path img to Base64.**
byte[] bytes = System.Text.UTF8Encoding.UTF8.GetBytes(image);
string base64String = System.Convert.ToBase64String(bytes);
MessageBox.Show("Base 64 String :[" + base64String + "]");
//Convert my img base64 to img.
byte[] fileBytes = Convert.FromBase64String(base64String);
using (MemoryStream ms = new MemoryStream(fileBytes, 0, fileBytes.Length))
{
ms.Write(fileBytes, 0, fileBytes.Length);
BitmapImage bitmapImage = new BitmapImage();
**bitmapImage.SetSource(ms);**
return bitmapImage;
}
}
}
This code don't work in my case because of setSource. I found this "solution" here : similar question 1 similar question 2
But they don't work in my case, i think it's because they didn't use the binding. And i don't have any idea to fix it...
Sorry for my english, and i hope someone can help me :)
Aucun commentaire:
Enregistrer un commentaire