LEADTOOLS Support
Medical
Medical SDK Questions
SetStringValue using GB18030 charset failed
#1
Posted
:
Wednesday, July 31, 2019 12:15:20 AM(UTC)
Groups: Registered
Posts: 21
I'm using LeadTools v20 kit to develop PACS worklist, because there's modality using GB18030 charset, and I found when I trying to use SetStringValue to set chinese patient name using GB18030 charset, it failed. It works well when I using UTF8 charset, Could anyone tell me how to set Unicode string to element using GB18030 charset? Following is my test code:
Quote:
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("SetStringValue Failed");
}
#2
Posted
:
Tuesday, August 6, 2019 11:06:44 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 54
Thanks: 2 times
Was thanked: 10 time(s) in 10 post(s)
Hello Devinzhu,
You should simply be able to do either of two options: Pass the string value and the character set as parameters to the DicomDataSet.SetStringValue method, or pass only the string value to the SetStringValue method after first inserting the character set as an element using the generic InsertElementAndSetValue method using the DicomTag.SpecificCharacterSet enum. You can find working examples for these as examples 1 and 3 on the following documentation page:
https://www.leadtools.com/help/leadtools/v20/dh/di/dicomdataset-setstringvalue(dicomelement,string,dicomcharactersettype).htmlHowever, I have verified that using the GB18030 character set causes issues as you have mentioned. I will report this to engineering to be fixed so that I can send you a hotfix that would resolve the issue. As an immediate fix, you can use the UnicodeInUtf8 character set instead which I have verified on my end to work properly. You can refer to my code for this below:
Code:DicomEngine.Startup();
DicomDataSet ds = new DicomDataSet();
DicomElement element = ds.InsertElement(null, false, DicomTag.PatientName, DicomVRType.PN, false, 0);
string text = "测试";
ds.SetStringValue(element, text, DicomCharacterSetType.UnicodeInUtf8);
string storedText = ds.GetStringValue(element, 0);
Debug.Assert(text == storedText);
Josh Clark
Developer Support Engineer
LEAD Technologies, Inc.
#3
Posted
:
Wednesday, August 7, 2019 5:44:04 AM(UTC)
Groups: Registered
Posts: 21
Thank you for your response and your code, Josh。I'll temporary using UTF8 for all Chinese characters in my code.
LEADTOOLS Support
Medical
Medical SDK Questions
SetStringValue using GB18030 charset failed
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.