整理影像缩略图 和获取影像路径
This commit is contained in:
@@ -271,6 +271,27 @@ public static class FileStoreHelper
|
||||
}
|
||||
|
||||
|
||||
public static string GetSubjectVisitDicomFolderPhysicalPath(IWebHostEnvironment _hostEnvironment,Guid trialId, Guid siteId, Guid subjectId, Guid subjectVisitId)
|
||||
{
|
||||
var rootPath = FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment);
|
||||
|
||||
return Path.Combine(rootPath, StaticData.Folder.TrialDataFolder, trialId.ToString(), siteId.ToString(), subjectId.ToString(), subjectVisitId.ToString(), StaticData.Folder.DicomFolder);
|
||||
}
|
||||
|
||||
public static string GetDicomInstanceFilePath(IWebHostEnvironment _hostEnvironment, Guid trialId, Guid siteId, Guid subjectId, Guid subjectVisitId, Guid studyId, Guid instanceId)
|
||||
{
|
||||
var rootPath = FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment);
|
||||
|
||||
//加入访视层级 和Data
|
||||
var path = Path.Combine(rootPath, StaticData.Folder.TrialDataFolder, trialId.ToString(),
|
||||
siteId.ToString(), subjectId.ToString(), subjectVisitId.ToString(), StaticData.Folder.DicomFolder, studyId.ToString());
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
return Path.Combine(path, instanceId.ToString() + ".dcm");
|
||||
}
|
||||
|
||||
|
||||
// 获取医生通用文件存放路径
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
|
||||
using FellowOakDicom.Imaging;
|
||||
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace IRaCIS.Core.Application.Helper;
|
||||
|
||||
public static class ImageHelper
|
||||
{
|
||||
|
||||
// 采用ImageSharp组件 跨平台,不依赖windows 平台图像处理组件,这里大坑(net 6 下,之前由于Dicom处理最新组件 依赖了这个库的一个旧版本,导致缩略图bug,单独升级依赖组件才解决)
|
||||
public static void ResizeSave(string filePath, string? fileStorePath)
|
||||
{
|
||||
|
||||
fileStorePath = fileStorePath ?? filePath + ".preview.jpeg";
|
||||
|
||||
using (var image = SixLabors.ImageSharp.Image.Load(filePath))
|
||||
{
|
||||
|
||||
image.Mutate(x => x.Resize(500, 500));
|
||||
|
||||
image.Save(fileStorePath);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Stream RenderPreviewJpeg(string filePath)
|
||||
{
|
||||
string jpegPath = filePath + ".preview.jpg";
|
||||
|
||||
if (!File.Exists(jpegPath))
|
||||
{
|
||||
using (Stream stream = new FileStream(jpegPath, FileMode.Create))
|
||||
{
|
||||
DicomImage image = new DicomImage(filePath);
|
||||
|
||||
var sharpimage = image.RenderImage().AsSharpImage();
|
||||
|
||||
sharpimage.Save(stream, new JpegEncoder());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return new FileStream(jpegPath, FileMode.Open);
|
||||
}
|
||||
|
||||
public static void RemovePreviewJpeg(string filePath)
|
||||
{
|
||||
string jpegPath = filePath + ".preview.jpg";
|
||||
if (File.Exists(jpegPath)) File.Delete(jpegPath);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static class IdentifierHelper
|
||||
{
|
||||
private static MD5 md5 = MD5.Create();
|
||||
|
||||
private static object lockObj = new object();
|
||||
|
||||
public static Guid CreateGuid(params string[] parts)
|
||||
{
|
||||
lock (lockObj)
|
||||
{
|
||||
return new Guid(md5.ComputeHash(Encoding.UTF8.GetBytes(string.Concat(parts))));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
|
||||
namespace IRaCIS.Core.Application.Helper;
|
||||
|
||||
public static class ImageResizeHelper
|
||||
{
|
||||
|
||||
// 采用ImageSharp组件 跨平台,不依赖windows 平台图像处理组件,这里大坑(net 6 下,之前由于Dicom处理最新组件 依赖了这个库的一个旧版本,导致缩略图bug,单独升级依赖组件才解决)
|
||||
public static void ResizeSave(string filePath, string? fileStorePath)
|
||||
{
|
||||
|
||||
fileStorePath = fileStorePath ?? filePath + ".preview.jpeg";
|
||||
|
||||
using (var image = SixLabors.ImageSharp.Image.Load(filePath))
|
||||
{
|
||||
|
||||
image.Mutate(x => x.Resize(500, 500));
|
||||
|
||||
image.Save(fileStorePath);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user