2016-04-02 88 views

回答

0

我相信你正试图将base64图像字符串转换为图像。 以下是你可以用将其转换为图像的代码:

public static Image LoadImage(string base64string) 
    { 
     byte[] bytes = Convert.FromBase64String(base64string); //Convert.FromBase64String("R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw=="); 

     Image image; 
     using (MemoryStream ms = new MemoryStream(bytes)) 
     { 
      image = Image.FromStream(ms); 
     } 
     return image; 
    } 

然后可以保存图片如下:

Image image = UtilityHelper.LoadImage(ch.Message); 
string imgname = ch.MobileNo + "_" +  DateTime.UtcNow.ToString("yyyyMMddHHmmssfff") + ".jpg"; 
string filepath = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~\\Images\\") + subPath + "\\" + imgname); 
var image2 = new Bitmap(image); 

image2.Save(filepath, ImageFormat.Jpeg); 
相关问题