/// <summary> /// 字节数组存储为文件 /// </summary> /// <param name="data"></param> /// <returns></returns> private static string Save2File(string dirname, byte[] data) { string fileName = GenerateFileName(DateTime.Now.Millisecond); string fileExt = ".jpg"; string fileFullName = fileName + fileExt; string tempDir = CommonInfo.ImageTempUrl + "/" + dirname; try { //创建临时文件夹,以日期为名称 if (!Directory.Exists(tempDir)) { Console.WriteLine("新创建" + tempDir); #region 日志输出 CommonInfo.Log("新创建" + tempDir); #endregion Directory.CreateDirectory(tempDir); } FileStream fs = new FileStream(tempDir + "/" + fileFullName, FileMode.Create, FileAccess.ReadWrite); fs.Write(data, 0, data.Length); fs.Close(); //裁剪图片 CommonInfo.ImageProcess(tempDir + "/" + fileFullName); } catch (Exception ex) { Console.WriteLine(ex.Message); #region 日志输出 CommonInfo.Error("保存图片错误" + ex.Message); #endregion return(String.Empty); } Console.WriteLine("图片保存成功"); return(fileFullName); }