public static void Dcm2Jpg(Dcm2JpgOptions options) { var file = DicomFile.Open(@options.dcmPath); var image = new DicomImage(file.Dataset); var patientid = file.Dataset.Get <string>(DicomTag.PatientID); if (string.IsNullOrEmpty(patientid)) { patientid = GetTimeStamp(); } int x = file.Dataset.Get <int>(DicomTag.NumberOfFrames); for (var i = 0; i < x; i++) { var fileName = options.outJpgDir + "/" + patientid + "_" + (i + 1) + ".jpg"; image.RenderImage(i).AsBitmap().Save(@fileName); } Console.WriteLine("success: dcm转jpg成功"); }
static async Task Main(string[] args) { // 如果未传参数,则直接返回 if (args.Length <= 1) { Console.WriteLine("请传入参数,如:"); Console.WriteLine("img2dcm \"{patientName:'xxx',patientID:'123',images:['1.jpg','2.jpg'],outDcm:'1.dcm'}\""); Console.WriteLine("dcm2jpg \"{'dcmPath':'E:/test/images/3.dcm','outJpgDir':'E:/test/images/outJpg'}\""); Console.WriteLine("dcmScu \"{'ip':'127.0.0.1','port':4242,'dcmPath':'E:/test/images/3.dcm'}\""); Console.ReadKey(); return; } Console.WriteLine(args[1]); // 解析命令行参数 // 图片转dcm if (args[0].Equals("img2dcm")) { Img2DcmOptions options = JsonConvert.DeserializeObject <Img2DcmOptions>(args[1]); Image2dcm(options); } // dcm转图片 if (args[0].Equals("dcm2jpg")) { Dcm2JpgOptions options = JsonConvert.DeserializeObject <Dcm2JpgOptions>(args[1]); Dcm2Jpg(options); } // dcm转图片 if (args[0].Equals("dcmScu")) { DcmScuOptions options = JsonConvert.DeserializeObject <DcmScuOptions>(args[1]); await DcmScu(options); } }