Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Wednesday, July 31, 2019 12:15:20 AM(UTC)
devinzhu

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");
}
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Tuesday, August 6, 2019 11:06:44 AM(UTC)
Josh Clark

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).html

However, 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.

LEAD Logo
 
#3 Posted : Wednesday, August 7, 2019 5:44:04 AM(UTC)
devinzhu

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.
 
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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.073 seconds.