下面这段是我的测试代码,我试了好久都无法把中文用GB18030的编码设置进去。麻烦帮我找个能把GB18030的字符串值设置进去的方法
DicomDataSet ds = new DicomDataSet();
ds.Initialize(DicomClassType.Undefined, DicomDataSetInitializeFlags.None);
ds.InsertElementAndSetValue(DicomTag.SpecificCharacterSet, "GB18030");
DicomElement element = ds.InsertElement(null, false, DicomTag.PatientName, DicomVRType.PN, false, 0);
Encoding utf8 = Encoding.GetEncoding("UTF-8");
Encoding gb18030 = Encoding.GetEncoding("GB18030");
byte[] gb = utf8.GetBytes("测试");
gb = Encoding.Convert(utf8, gb18030, gb);
if (!ds.SetStringValue(element, gb18030.GetString(gb), DicomCharacterSetType.Gb18030))
{
System.Console.WriteLine("Set Value Failed");
} |