LindDotNetCore ~ Chinese garbled characters are generated on images in docker,

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.