Convert Base64 string to BitmapImage C# Windows Phone

后端 未结 1 1246
别跟我提以往
别跟我提以往 2021-01-20 17:33

I receive a image/jpeg;base64 string from server. How can I convert this string to BitmapImage and set like Image.Source ?

string imgStr = \"data:image/jpeg;         


        
相关标签:
1条回答
  • 2021-01-20 17:37

    I find solution for my issue:

    public static BitmapImage Base64StringToBitmap(string  base64String)
    {
        byte[] byteBuffer = Convert.FromBase64String(base64String);
        MemoryStream memoryStream = new MemoryStream(byteBuffer);
        memoryStream.Position = 0;
    
        BitmapImage bitmapImage = new BitmapImage();
        bitmapImage.SetSource(memoryStream);
    
        memoryStream.Close();
        memoryStream = null;
        byteBuffer = null;
    
        return bitmapImage;
    }
    
    0 讨论(0)
提交回复
热议问题