体检系统架构
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

42 lines
1.5 KiB

using System.Threading.Channels;
using FellowOakDicom;
using FellowOakDicom.Imaging;
using SixLabors.ImageSharp;
namespace DcmToPng.Helper
{
public class DcmToPngHelper
{
public static void Convert()
{
new DicomSetupBuilder()
.RegisterServices(s => s.AddFellowOakDicom().AddImageManager<ImageSharpImageManager>())
.Build();
if (!Directory.Exists(Constant.ImgPath))
Directory.CreateDirectory(Constant.ImgPath);
var dicomFiles = Directory.GetFiles(Constant.DcmPath, "*.dcm"); // 获取所有.dcm
Console.WriteLine("[待转换的DCM文件]" + dicomFiles.Length);
int i=0;
foreach (var filePath in dicomFiles)
{
try
{
if (File.Exists(Path.GetFileNameWithoutExtension(filePath) + ".png"))
continue;
var image = new DicomImage(filePath);
var bitmap = image.RenderImage().AsSharpImage();
string outputPath = Path.Combine(Constant.ImgPath, Path.GetFileNameWithoutExtension(filePath) + ".png");
bitmap.SaveAsJpeg(outputPath);
File.Delete(filePath);
i++;
}
catch (Exception e)
{
Console.WriteLine("[Convert]" + e.Message);
}
}
Console.WriteLine("[转换成功]" + i);
}
}
}