处理scp服务 拆分影像

Test_HIR_Net8
hang 2025-08-29 11:36:27 +08:00
parent 4945daa0d4
commit a19ba3c215
2 changed files with 59 additions and 2 deletions

View File

@ -24,6 +24,8 @@ using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Infrastructure.Extention; using IRaCIS.Core.Infrastructure.Extention;
using Newtonsoft.Json; using Newtonsoft.Json;
using FellowOakDicom.Imaging.Codec; using FellowOakDicom.Imaging.Codec;
using FellowOakDicom.IO.Buffer;
using System.Diagnostics.CodeAnalysis;
namespace IRaCIS.Core.SCP.Service namespace IRaCIS.Core.SCP.Service
{ {
@ -237,7 +239,7 @@ namespace IRaCIS.Core.SCP.Service
} }
else else
{ {
Log.Logger.Error($"未找到{g.Key.StudyInstanceUid}的Cmove记录"); Log.Logger.Warning($"未找到{g.Key.StudyInstanceUid}的Cmove记录");
} }
} }
@ -319,6 +321,7 @@ namespace IRaCIS.Core.SCP.Service
long fileSize = 0; long fileSize = 0;
try try
{ {
@ -326,7 +329,61 @@ namespace IRaCIS.Core.SCP.Service
{ {
await request.File.SaveAsync(ms); await request.File.SaveAsync(ms);
#region 1帧拆成多个固定大小的方便移动端浏览
// 回到开头,读取 dicom
ms.Position = 0;
var dicomFile = DicomFile.Open(ms);
var pixelData = DicomPixelData.Create(dicomFile.Dataset);
var syntax = pixelData.Syntax;
// 每个 fragment 固定大小 (64KB 示例,可以自己调整)
int fragmentSize = 20 * 1024;
if (syntax.IsEncapsulated)
{
var newFragments = new DicomOtherByteFragment(DicomTag.PixelData);
for (int n = 0; n < pixelData.NumberOfFrames; n++)
{
var frameData = pixelData.GetFrame(n); // 获取完整一帧
var data = frameData.Data;
int offset = 0;
while (offset < data.Length)
{
int size = Math.Min(fragmentSize, data.Length - offset);
var buffer = new byte[size];
Buffer.BlockCopy(data, offset, buffer, 0, size);
newFragments.Fragments.Add(new MemoryByteBuffer(buffer));
offset += size;
}
}
// 替换原 PixelData
dicomFile.Dataset.AddOrUpdate(newFragments);
}
// 重新保存 dicom 到流
ms.SetLength(0);
dicomFile.Save(ms);
ms.Position = 0;
#endregion
#region 本地测试
//// --- 保存到本地文件测试 ---
//var localPath = @"D:\TestDicom.dcm";
//using (var fs = new FileStream(localPath, FileMode.Create, FileAccess.Write))
//{
// ms.CopyTo(fs);
//}
//return new DicomCStoreResponse(request, DicomStatus.Success);
#endregion
//irc 从路径最后一截取Guid //irc 从路径最后一截取Guid

View File

@ -13604,7 +13604,7 @@
</summary> </summary>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:IRaCIS.Core.Application.Service.HospitalGroupService.GetGAUserList"> <member name="M:IRaCIS.Core.Application.Service.HospitalGroupService.GetGAUserList(System.Guid)">
<summary> <summary>
GA用户列表 GA用户列表
</summary> </summary>