20210813 对接门禁接口调整

This commit is contained in:
2021-08-13 10:48:08 +08:00
parent bacbffb714
commit 43acc57060
37 changed files with 345 additions and 68 deletions
+42
View File
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
namespace BLL
{
@@ -414,5 +416,45 @@ namespace BLL
}
}
#endregion
/// <summary>
///
/// </summary>
/// <param name="base64Str"></param>
/// <param name="path"></param>
/// <param name="imgName"></param>
/// <returns></returns>
public static string Base64ToImage(string base64Str, string path, string imgName)
{
string filename = "";//声明一个string类型的相对路径
String base64 = base64Str.Substring(base64Str.IndexOf(",") + 1); //将‘,’以前的多余字符串删除
System.Drawing.Bitmap bitmap = null;//定义一个Bitmap对象,接收转换完成的图片
try//会有异常抛出,try,catch一下
{
byte[] arr = Convert.FromBase64String(base64);//将纯净资源Base64转换成等效的8位无符号整形数组
System.IO.MemoryStream ms = new System.IO.MemoryStream(arr);//转换成无法调整大小的MemoryStream对象
bitmap = new System.Drawing.Bitmap(ms);//将MemoryStream对象转换成Bitmap对象
filename = path + imgName + ".jpg";//所要保存的相对路径及名字
string url = ConfigurationManager.AppSettings["localRoot"];
string tmpRootDir = System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString()); //获取程序根目录
string imagesurl2 = tmpRootDir + filename; //转换成绝对路径
bitmap.Save(imagesurl2, System.Drawing.Imaging.ImageFormat.Jpeg);//保存到服务器路径
//bitmap.Save(filePath + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
//bitmap.Save(filePath + ".gif", System.Drawing.Imaging.ImageFormat.Gif);
//bitmap.Save(filePath + ".png", System.Drawing.Imaging.ImageFormat.Png);
ms.Close();//关闭当前流,并释放所有与之关联的资源
bitmap.Dispose();
}
catch (Exception e)
{
string massage = e.Message;
}
return filename;//返回相对路径
}
}
}