[vtkusers] vtkDICOMReader read chinese character problem

David Gobbi david.gobbi at gmail.com
Thu Mar 30 23:41:32 EDT 2017


On Thu, Mar 30, 2017 at 8:52 PM, Ang <ysa0829 at gmail.com> wrote:

> Hi David,
>
> My character default setting is UTF-8 and the Transfer Syntax UID is
> "1.2.840.10008.1.2.4.91"
> .
>
> Finally, I found the solution that gdcmReader needs the filename to be
> ansi(I guess), I add below code in vtkDICOMReader at line 1460 to 1470.
>
> ***********************************************
>
>   gdcm::ImageReader reader;
>
>   int len = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);
>   wchar_t* wfilename = new wchar_t[len + 1];
>   memset(wfilename, 0, len * 2 + 2);
>   MultiByteToWideChar(CP_UTF8, 0, filename, -1, wfilename, len);
>   len = WideCharToMultiByte(CP_ACP, 0, wfilename, -1, NULL, 0, NULL, NULL);
>   char* szfilename = new char[len + 1];
>   memset(szfilename, 0, len + 1);
>   WideCharToMultiByte(CP_ACP, 0, wfilename, -1, szfilename, len, NULL,
> NULL);
>   std::string strTemp(szfilename);
>   if (wfilename) delete[] wfilename;
>   if (szfilename) delete[] szfilename;
>   reader.SetFileName(strTemp.c_str());
>
> ****************************************************
>
> Is this solution better?
>


Yes, that is the correct solution, since your ANSI character set is Chinese.
Because vtkDICOMReader uses gdcm for decompression, it is necessary
to do this conversion if you use any compressed transfer syntax.

Most of the VTK readers use ANSI on Windows.  Personally, I think that it
would be better if they all used utf-8 (and if gdcm used utf-8, too).
Especially
since the the native character set on Windows and NTFS is Unicode.

 - David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170330/0737514a/attachment.html>


More information about the vtkusers mailing list