Google Zxing依赖在linux服务器上生成二维码图片中带有中文显示不了的问题。

一,问题描述

在二维码中显示的图片中含有中文,不显示而是显示乱码。这是因为linux系统中为安装中文。

二,解决方法

1、查看所有字体:fc-list // 如果提示 fc-list: command not found,则需要安装# yum install fontconfig

2、查看是否有中文字体:fc-list :lang=zh , 如果显示空,说明没有

 

3. 在/usr/shared/fonts目录下新建一个目录chinese

 

4、修改权限, chmod -R 755 /usr/share/fonts/chinese
5、到windows系统 C:\Windows\Fonts 目录下找到宋体

 

 

6、将 宋体 上传到centos /usr/share/fonts/chinese 目录下

7、然后执行ttmkfdir命令:

        ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.di

若提示mkfontscale command not found,则运行yum -y install ttmkfdir

 8、修改字体配置文件了,首先通过编辑器打开配置文件:

vi /etc/fonts/fonts.conf

  新增配置 <dir>/usr/share/fonts/chinese</dir>

 

8、保存退出编辑

9、刷新字体缓存

 fc-cache

 10、查看是否安装成功 fc-list :lang=zh

 三,最后修改中文字体

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当使用ZXing.ImageSharp.V2组件生成二维码图片,并在图片上包含二维码和提示文字时,并且要求兼容Linux系统,你可以按照以下步骤进行操作: 首先,确保你的项目已安装了ZXing.Net库和ImageSharp库,可以通过NuGet包管理器进行安装。 接下来,你可以使用以下代码方法来生成带有二维码和提示文字图片: ```csharp using System; using System.IO; using System.Text; using SixLabors.Fonts; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Processing; using ZXing; using ZXing.Common; public class QrCodeGenerator { public static void GenerateQrCodeWithText(string content, string text, string outputPath) { // 生成二维码 BarcodeWriter writer = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new EncodingOptions { Width = 300, Height = 300 } }; using (var qrCodeImage = writer.Write(content)) { // 加载字体 var fontCollection = new FontCollection(); var font = fontCollection.Install("path/to/your/font.ttf"); // 创建画布 var image = new Image<Rgba32>(500, 500); image.Mutate(ctx => { ctx.Fill(Rgba32.White); ctx.DrawImage(qrCodeImage, new Point(100, 100), 1f); ctx.DrawText(new TextGraphicsOptions { TextOptions = new TextOptions { FontSize = 24, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom, ApplyKerning = true }, WrapTextWidth = 300 }, text, font, Rgba32.Black, new PointF(250, 400)); }); // 保存图片 image.Save(outputPath); } } } ``` 在上述代码,你需要将`"path/to/your/font.ttf"`替换为你自己的字体文件路径。此外,你可以根据需要调整二维码的大小、文字的大小和位置等参数。 最后,调用该方法并传入相应的参数即可生成带有二维码和提示文字图片: ```csharp string content = "Your content here"; string text = "Your text here"; string outputPath = "path/to/output/image.png"; QrCodeGenerator.GenerateQrCodeWithText(content, text, outputPath); ``` 请注意,该方法需要在支持ImageSharp和ZXing.Net的环境运行,因此确保已将这些库安装到你的项目,并引入相关命名空间。 希望以上代码能满足你的需求,如果有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值