C# 如何在运行时将TIFF转换为png/jpg并在Asp.NETCore中显示?

C# 如何在运行时将TIFF转换为png/jpg并在Asp.NETCore中显示?,c#,html,imageview,memorystream,asp.net-core-3.0,C#,Html,Imageview,Memorystream,Asp.net Core 3.0,我使用Asp.Net Core 3.0,我需要在运行时和显示中将TIFF字符串转换为png/jpg图像 它但是我解决了这个问题ArgumentException:参数无效。System.Drawing.Image.FromStream(Stream-Stream,bool 使用EmbeddedColorManagement,bool validateImageData) 首先:我所做的 我从XML文件中读取TIFF字符串,如下代码所示 [HttpGet] public async Task<

我使用Asp.Net Core 3.0,我需要在运行时显示中将TIFF字符串转换为png/jpg图像 但是我解决了这个问题
ArgumentException:参数无效。System.Drawing.Image.FromStream(Stream-Stream,bool
使用EmbeddedColorManagement,bool validateImageData)

首先:我所做的

  • 我从XML文件中读取TIFF字符串,如下代码所示
  • [HttpGet]

    public async Task<IActionResult> ReadData()
    {
       XmlDocument document = new XmlDocument();
       document.Load(@"Location In the Computer\MyFile.xml");
       XmlNodeList sign = document.GetElementsByTagName("sign");
       byte[] buffer = Encoding.ASCII.GetBytes(sign.Item(0).InnerText);
       ViewBag.Sign = ConvertTiffToImage(buffer); //This method convert tiff to png/jpg
       return View("Create");
    }
    
  • 我尝试使用ViewBag显示图像,如下代码所示

  • private string ConvertTiffToImage(byte[] tiffBytes)
    {
        //Read the tiff and convert to png
        MemoryStream ms = new MemoryStream(tiffBytes);
        MemoryStream newMS = new MemoryStream();
        Bitmap.FromStream(ms).Save(newMS, ImageFormat.Png); //Error come here
    
        //Read the converted memorystream and insert it to string to display
        StreamReader reader = new StreamReader(newMS);
        string pngImage = reader.ReadToEnd();
        return pngImage;
    }
    
    @if(ViewBag.Sign==null)
    {
    }
    其他的
    {
    }