From 274a8d2c210c77f6606d6a9084a5710484da9499 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Sun, 4 Jan 2026 18:35:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E9=99=A4=E5=BA=93=E7=9A=84=E5=8E=9F?= =?UTF-8?q?=E5=9B=A0=EF=BC=8C=E7=BC=A9=E7=95=A5=E5=9B=BE=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRC.Core.SCP/Program.cs | 3 + IRC.Core.SCP/Service/PatientStudyService.cs | 71 +++++++++++++++++---- 2 files changed, 63 insertions(+), 11 deletions(-) diff --git a/IRC.Core.SCP/Program.cs b/IRC.Core.SCP/Program.cs index b3d4a885c..544d38a4d 100644 --- a/IRC.Core.SCP/Program.cs +++ b/IRC.Core.SCP/Program.cs @@ -167,6 +167,9 @@ var app = builder.Build(); //app.UseSwaggerUI(); //} +//不需要 token 访问的静态文件 wwwroot css, JavaScript, and images don't require authentication. +app.UseStaticFiles(); + SwaggerSetup.Configure(app, app.Environment); app.UseAuthorization(); diff --git a/IRC.Core.SCP/Service/PatientStudyService.cs b/IRC.Core.SCP/Service/PatientStudyService.cs index 8b817ae22..f55b93ebc 100644 --- a/IRC.Core.SCP/Service/PatientStudyService.cs +++ b/IRC.Core.SCP/Service/PatientStudyService.cs @@ -1,19 +1,22 @@ -using IRaCIS.Core.Domain.Share; -using System.Text; -using Microsoft.AspNetCore.Hosting; -using IRaCIS.Core.Infrastructure; -using Medallion.Threading; -using FellowOakDicom; +using FellowOakDicom; +using FellowOakDicom.Imaging; using FellowOakDicom.Imaging.Codec; -using System.Data; -using IRaCIS.Core.Domain.Models; using FellowOakDicom.Network; -using IRaCIS.Core.SCP.Service; +using IRaCIS.Core.Domain.Models; +using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infra.EFCore; -using MassTransit; -using Microsoft.AspNetCore.Mvc; +using IRaCIS.Core.Infrastructure; using IRaCIS.Core.Infrastructure.Extention; +using IRaCIS.Core.SCP.Service; +using MassTransit; +using Medallion.Threading; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using SixLabors.ImageSharp.Formats.Jpeg; +using System.Data; +using System.Text; namespace IRaCIS.Core.SCP.Service { @@ -46,7 +49,53 @@ namespace IRaCIS.Core.SCP.Service _distributedLockProvider = distributedLockProvider; } + [AllowAnonymous] + public async Task TestImage(string folderPath) + { + if (!Directory.Exists(folderPath)) + return ResponseOutput.Ok("目录不存在"); + + // 获取所有 .dcm 文件 + var dicomFiles = Directory.GetFiles(folderPath); + + foreach (var fileFullPath in dicomFiles) + { + try + { + var file = await DicomFile.OpenAsync(fileFullPath); + + + // 生成缩略图 + using (var memoryStream = new MemoryStream()) + { + DicomImage image = new DicomImage(file.Dataset); + + var sharpimage = image.RenderImage().AsSharpImage(); + sharpimage.Save(memoryStream, new JpegEncoder()); + + + // 关键点:一定要回到开头 + memoryStream.Position = 0; + + using (var fileStream = File.Create($"{fileFullPath}.jpg")) + { + await memoryStream.CopyToAsync(fileStream); + } + + } + } + catch (Exception) + { + + continue; + } + } + + + + return ResponseOutput.Ok(); + } public class AuToBindingStudyInfo {