c#: how to read parts of a file? (DICOM)

后端 未结 4 1787
[愿得一人]
[愿得一人] 2020-12-14 21:55

I would like to read a DICOM file in C#. I don\'t want to do anything fancy, I just for now would like to know how to read in the elements, but first I would actually like

4条回答
  •  盖世英雄少女心
    2020-12-14 22:40

    Just some pseudologic

    How to I read the header file and verify if it is a DICOM file by checking for the 'D','I','C','M' characters after the 128 byte preamble?

    • Open as binary file, using File.OpenRead
    • Seek to position 128 and read 4 bytes into the array and compare it againts byte[] value for DICM. You can use ASCIIEncoding.GetBytes() for that

    How do I continue to parse the file reading the other parts of the data?

    • Continue reading the file using Read or ReadByte using the FileStream object handle that you have earlier
    • Use the same method like above to do your comparison.

    Dont forget to close and dispose the file.

提交回复
热议问题