How to set dicomfile encoding

599 Views Asked by At

fo-dicom 4.0.6.

netcore5

I create dicom files based on existing one. Only adding few tags in cyrillic As I understand when I open dicomfile, tag SpecificCharacterSet is used to define tag's value encoding. Bu as I understand I can change this behavior with custom IOManager.

F.ex. if I want force encoding 1251 I can define class

public class AnsiIOManager : IOManager
{
    /// <inheritdoc />
    protected override Encoding BaseEncodingImpl => Encoding.GetEncoding("windows-1251");

    ...
}

And to assign this by IOManager.SetImplementation(new AnsiIOManager());

Am I right?

Sometimes I need to create files in different encoding at the same time in multithreading. And can I change this IOManager encoding dinamically instead of change static type value?

1

There are 1 best solutions below

4
gofal3 On

Changing the default encoding in IOManager is not the right way to do that. Because you add some value to a a DicomDataset and therefore also need to update the SpeicificCharacterSet in that file. The IOManager only influences the default encoding used when parsing values. All this encoding this have been improved dramatically in version 5.0.0. So I recommend, to use fo-dicom 5.0.0. Then you can do the following:

  • load the DicomDataset
  • call dataset.AddOrUpdate(DicomTag.SpeicificCharacterSet, DicomEncoding.GetCharset( Encoding.GetEncoding("windows-1251") )), so telling the dataset, now to use the encoding you desire
  • add Tags with string values