|
|
@ -275,86 +275,46 @@ namespace Shentun.Peis |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static string Base64ToImageInAbsolutePath(string AbsolutePath, string fileName, string base64Str, string PatientRegisterId, string RegisterCheckId) |
|
|
|
|
|
|
|
|
public static string Base64ToImageUseAbsolutePath(string absolutePath, string fileName, string base64Str, string patientRegisterId, string registerCheckId) |
|
|
{ |
|
|
{ |
|
|
var ret = ""; |
|
|
var ret = ""; |
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(absolutePath)) |
|
|
{ |
|
|
{ |
|
|
|
|
|
throw new UserFriendlyException("absolutePath不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
base64Str = base64Str.Substring(base64Str.IndexOf(",") + 1); |
|
|
|
|
|
|
|
|
|
|
|
string savePath = ""; |
|
|
|
|
|
string hostPath = ""; |
|
|
|
|
|
var bitmap = Base64StrToImage(base64Str); |
|
|
|
|
|
|
|
|
|
|
|
if (bitmap != null) |
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(fileName)) |
|
|
{ |
|
|
{ |
|
|
string ImageSuffix = ""; |
|
|
|
|
|
if (ImageFormat.Png.Guid == bitmap.RawFormat.Guid) |
|
|
|
|
|
{ |
|
|
|
|
|
ImageSuffix = ".png"; |
|
|
|
|
|
|
|
|
throw new UserFriendlyException("文件名不能为空"); |
|
|
} |
|
|
} |
|
|
else if (ImageFormat.Gif.Guid == bitmap.RawFormat.Guid) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(base64Str)) |
|
|
{ |
|
|
{ |
|
|
ImageSuffix = ".gif"; |
|
|
|
|
|
|
|
|
throw new UserFriendlyException("base64Str不能为空"); |
|
|
} |
|
|
} |
|
|
else if (ImageFormat.Bmp.Guid == bitmap.RawFormat.Guid) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(patientRegisterId)) |
|
|
{ |
|
|
{ |
|
|
ImageSuffix = ".bmp"; |
|
|
|
|
|
|
|
|
throw new UserFriendlyException("PatientRegisterId不能为空"); |
|
|
} |
|
|
} |
|
|
else |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(registerCheckId)) |
|
|
{ |
|
|
{ |
|
|
ImageSuffix = ".jpg"; |
|
|
|
|
|
|
|
|
throw new UserFriendlyException("RegisterCheckId不能为空"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
string savaDirectory = $"{AbsolutePath}\\pacs\\{DateTime.Now.Year}\\{DateTime.Now.Month}\\{DateTime.Now.Day}\\{PatientRegisterId}\\{RegisterCheckId}"; |
|
|
|
|
|
|
|
|
|
|
|
savePath = $"{savaDirectory}\\{fileName + ImageSuffix}"; |
|
|
|
|
|
hostPath = $"/CheckPictureImg/pacs/{DateTime.Now.Year}/{DateTime.Now.Month}/{DateTime.Now.Day}/{PatientRegisterId}/{RegisterCheckId}/{fileName + ImageSuffix}"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string savaDirectory = $"{absolutePath}\\pacs\\{DateTime.Now.Year}\\{DateTime.Now.Month}\\{DateTime.Now.Day}\\{patientRegisterId}\\{registerCheckId}"; |
|
|
if (!Directory.Exists(savaDirectory)) |
|
|
if (!Directory.Exists(savaDirectory)) |
|
|
{ |
|
|
{ |
|
|
Directory.CreateDirectory(savaDirectory); |
|
|
Directory.CreateDirectory(savaDirectory); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//图片后缀格式
|
|
|
|
|
|
var suffix = savePath.Substring(savePath.LastIndexOf('.') + 1, savePath.Length - savePath.LastIndexOf('.') - 1).ToLower(); |
|
|
|
|
|
var suffixName = suffix == "png" ? ImageFormat.Png : |
|
|
|
|
|
suffix == "jpg" || suffix == "jpeg" ? ImageFormat.Jpeg : |
|
|
|
|
|
suffix == "bmp" ? ImageFormat.Bmp : |
|
|
|
|
|
suffix == "gif" ? ImageFormat.Gif : ImageFormat.Jpeg; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//这里复制一份对图像进行保存,否则会出现“GDI+ 中发生一般性错误”的错误提示
|
|
|
|
|
|
var bmpNew = new Bitmap(bitmap); |
|
|
|
|
|
// bmpNew.Save(_hostingEnvironment.ContentRootPath + savePath, suffixName);
|
|
|
|
|
|
|
|
|
|
|
|
var s1 = Directory.GetCurrentDirectory(); |
|
|
|
|
|
|
|
|
|
|
|
string saveurl = Path.Combine(s1, savePath); |
|
|
|
|
|
|
|
|
|
|
|
bmpNew.Save(saveurl, suffixName); |
|
|
|
|
|
bmpNew.Dispose(); |
|
|
|
|
|
|
|
|
|
|
|
bitmap.Dispose(); |
|
|
|
|
|
|
|
|
var savePath = $"{savaDirectory}\\{fileName}"; |
|
|
|
|
|
var fullFileName = Base64ToImage(base64Str, savePath); |
|
|
|
|
|
var ImageSuffix = Path.GetExtension(fullFileName); |
|
|
|
|
|
var hostPath = $"/CheckPictureImg/pacs/{DateTime.Now.Year}/{DateTime.Now.Month}/{DateTime.Now.Day}/{patientRegisterId}/{registerCheckId}/{fileName + ImageSuffix}"; |
|
|
|
|
|
|
|
|
ret = hostPath; |
|
|
ret = hostPath; |
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
ret = ""; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
{ |
|
|
|
|
|
ret = ""; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -482,8 +442,19 @@ namespace Shentun.Peis |
|
|
return bitmap; |
|
|
return bitmap; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static void ConvertFromBase64(string base64String, string filePath) |
|
|
|
|
|
|
|
|
public static string Base64ToImage(string base64String, string filePath) |
|
|
|
|
|
{ |
|
|
|
|
|
if (string.IsNullOrWhiteSpace(filePath)) |
|
|
{ |
|
|
{ |
|
|
|
|
|
throw new UserFriendlyException("文件名不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(base64String)) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new UserFriendlyException("base64Str不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte[] imageBytes = Convert.FromBase64String(base64String); |
|
|
byte[] imageBytes = Convert.FromBase64String(base64String); |
|
|
using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) |
|
|
using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) |
|
|
{ |
|
|
{ |
|
|
@ -508,7 +479,8 @@ namespace Shentun.Peis |
|
|
{ |
|
|
{ |
|
|
ImageSuffix = ".jpg"; |
|
|
ImageSuffix = ".jpg"; |
|
|
} |
|
|
} |
|
|
image.Save(filePath); |
|
|
|
|
|
|
|
|
image.Save(filePath + ImageSuffix); |
|
|
|
|
|
return filePath + ImageSuffix; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|