Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ISO_IR 58 support in .Net 4.0

There is a double byte character set in DICOM named ISO_IR 58. As far as I can tell the equivalent encoding for this in .Net is gb2312. I am trying to encode ISO_IR 58 characters in 7 bit ASCII for communication between medical systems.

In the java world the string gb2312 works to do this encoding.

First look at this example for ISO_IR 87 (ISO_IR 87 equals iso-2022-jp in .Net):

Encoding enc = Encoding.GetEncoding("iso-2022-jp");
byte[] bytes = enc.GetBytes("叙収參参^去厰厦厘=却占^卮博南");
string asciistring = ASCIIEncoding.ASCII.GetString(bytes);

This takes the input string and gives the ASCII string: $B=v<}RT;2(B^$B5nRRRONR(B=$B5Q@j(B^$BRHGnFn(B

with all proper escape sequences with which I can use correctly.

(the actual first escape character does not display here but the rest of the sequence does when pasted)

If I use this code with characters from ISR_IR 58:

Encoding enc = Encoding.GetEncoding("gb2312");
byte[] bytes = enc.GetBytes("ㄆㄉㄊㄋ^ㄌㄍㄐㄓ^ㄖㄠㄢㄤ");
string asciistring = ASCIIEncoding.ASCII.GetString(bytes);

I only get the string: ????????^????????^????????

So what is the answer to DICOM ISO_IR 58 encoding using .Net? Am I using the wrong string for encoding? Is ISO_IR 58 in DICOM not supported in .Net? Is there a bug in .Net? Is it even possible?

like image 482
Jake Avatar asked Feb 09 '23 00:02

Jake


1 Answers

ASCIIEncoding is an 7-bit encoding and any 8-bit encoding cannot be represented with it. Hence the question marks.

This should work for all the charsets:

Encoding enc = Encoding.GetEncoding("gb2312");
byte[] bytes = enc.GetBytes("ㄆㄉㄊㄋ^ㄌㄍㄐㄓ^ㄖㄠㄢㄤ");

Encoding asc = Encoding.GetEncoding("iso-8859-1");
string astr = asc.GetString(bytes);

Output

A8 C6 A8 C9 A8 CA A8 CB 5E A8 CC A8 CD A8 D0 A8 D3 5E A8 D6 A8 E0 A8 E2 A8 E4 
¨Æ¨É¨Ê¨Ë^¨Ì¨Í¨Ð¨Ó^¨Ö¨à¨â¨ä
like image 54
codeDr Avatar answered Feb 20 '23 03:02

codeDr