Reputation: 100
I have a jpg strign stored in "(string)HttpContext.Current.Session["image" + 0];" that I am trying to convert to a System.Drawing.Image.
I know the string is correct, because when I do this -
img.Src = "data:image/jpg;base64," + (string)HttpContext.Current.Session["image" + 0];
Everying works as intended.
But when I do this -
string inputString = (string)HttpContext.Current.Session["image" + 0];
byte[] imageBytes = Convert.FromBase64String(inputString);
using (MemoryStream ms = new MemoryStream(imageBytes))
{
System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);
}
I get and error telling me the format is incorrect when trying to create an image from the stream.
Please help
Upvotes: 0
Views: 1212
Reputation: 528
don't you need to convert webp to jpg/png first? for example WebP-wrapper
using (WebP webp = new WebP())
{
var image = webp.Decode(imageBytes );
}
Upvotes: 1