Converting from string to Image in C#

前端 未结 5 2094
生来不讨喜
生来不讨喜 2021-02-20 06:22

I am trying to convert a Unicode string to an image in C#. Each time I run it I get an error on this line

Image image = Image.FromStream(ms, true, true);
         


        
5条回答
  •  耶瑟儿~
    2021-02-20 07:04

    May this can help you:

    public Bitmap stringToImage(string inputString)
    {
       byte[] imageBytes = Encoding.Unicode.GetBytes(inputString);
       using (MemoryStream ms = new MemoryStream(imageBytes))
       {
           return new Bitmap(ms);
       }
    }
    

提交回复
热议问题