LindDotNetCore ~ Chinese garbled characters are generated on images in docker,
Back to directory
Because most of the images on docker are based on the linux system, you need to consider the Chinese font issue when writing to the image, for example, in microsoft/aspnetcore2.0, it is based on the debian system and has only one English font on it, so garbled characters will appear when outputting Chinese characters. This is normal. Our solution also needs to follow the steps below!
Code for solving the problem
One dockerfile dynamically adds fonts and refreshes
FROM microsoft/aspnetcore:2.0WORKDIR /appEXPOSE 80RUN lsCOPY publish .COPY sources.list /etc/apt/sources.listRUN apt-get update && apt-get -y install libgdiplus RUN apt-get -y install fonts-wqy-zenhei && apt-get clean && fc-cache -fvENTRYPOINT ["dotnet", "FileUpload.dll"]
2. Produce Chinese fonts in System. Drawing
Font fTitle = new Font ("", 16); Font fText = new Font ("WenQuanYi Zen Hei", 9 );
3 At the same time, you can enter the container to view installed Chinese Fonts
Fc-list: lang = zh //: there is a space before the code.
In fact, the text is displayed in the Chinese font supported by the linux operating system where the current container is located. You need to use the above font when outputting Chinese characters on the image!
For details about how to build the System. Drawing environment on dotnetcore, refer to this article: DotNetCore cross-platform ~ Notes for deploying Linux using System. DrawingCore
Thank you for reading!
Back to directory