我有web应用程序,它会将图像转换为base64字符串。将它传递给WCF服务,serivce方法将字符串转换回png
图像。
客户端(将图像转换为Base 64)
public static string ImageToBase64(string path)
{
using (Image image = Image.FromFile(path))
{
using (MemoryStream m = new MemoryStream())
{
image.Save(m, image.RawFormat);
byte[] imageBytes = m.ToArray();
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
}
}
WCF服务方法
CommonDataManager.Base64ToImage(designImage).Save(designQuotePath + "/" + "Request_Quote_" + objQuote.Customer_Id.ToString(), ImageFormat.Png);
public static Image Base64ToImage(string base64String)
{
Image image = null;
try
{
byte[] imageBytes = System.Convert.FromBase64String(base64String);
using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
{
image = Image.FromStream(ms, true);
}
}
catch (Exception ex)
{
LogManager.LogException(ex, "Base64ToImage");
}
return image;
}
问题:
.png
文件。提前致谢。
答案 0 :(得分:0)
您需要添加扩展程序。更新此:
CommonDataManager.Base64ToImage(designImage).Save(designQuotePath + "/" +
"Request_Quote_" + objQuote.Customer_Id.ToString(), ImageFormat.Png);
要
CommonDataManager.Base64ToImage(designImage).Save(designQuotePath + "/" +
"Request_Quote_" + objQuote.Customer_Id.ToString() + ".png", ImageFormat.Png);