2016-04-02 117 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); 
相關問題