简体   繁体   English

将jpg字符串转换为图像

[英]Convert jpg string to image

I have a jpg strign stored in "(string)HttpContext.Current.Session["image" + 0];"我有一个 jpg 字符串存储在“(string)HttpContext.Current.Session["image" + 0];" that I am trying to convert to a System.Drawing.Image.我正在尝试转换为 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.尝试从 stream 创建图像时,我收到错误消息,告诉我格式不正确。

Please help请帮忙

don't you need to convert webp to jpg/png first?您不需要先将 webp 转换为 jpg/png 吗? for example WebP-wrapper例如WebP 包装器

    using (WebP webp = new WebP())
    {
      var image = webp.Decode(imageBytes );
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM