I tried to change Window Center in Dataset ( It is a tag with VR=DS and value type of ushort ).
But when we are using the following statement to change this property, the program throws an exception
DicomImage _image = new DicomImage("C:\\IM1");
DicomDataset dset = _image.Dataset;
dset.Add<ushort>(DicomTag.WindowCenter, (ushort)40);
we also tried it with type <decimal> and <int> and still problem is the same.
That is the error message:
Unable to create DICOM element of type DS with values of type System.Int32
We had to hard-coded this way to make it work (in DicomDataset class):
if (vr == DicomVR.DS)
{
if (values == null)
return Add(new DicomDecimalString(tag, EmptyBuffer.Value));
if (typeof(T) == typeof(decimal))
return Add(new DicomDecimalString(tag, values.Cast<decimal>().ToArray()));
if (typeof(T) == typeof(string))
return Add(new DicomDecimalString(tag, values.Cast<string>().ToArray()));
if (typeof(T) == typeof(int))
{
return Add(new DicomDecimalString(tag, new decimal[] { 40 }));
}
}
Is there any better way to change DicomTag values inside a DicomDataset?