You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell向图片插入希伯来语文字如何实现从右至左正确显示

解决方案

你可以通过System.Drawing.StringFormat类指定文本排版方向为从右到左,即可适配希伯来语的读写习惯,修改后的完整代码如下:

Add-Type -AssemblyName System.Drawing
$uname='סער'#Read-Host "insert name:"
$job='יינחןינצל'#Read-Host "insert job:"
$filename = "$home\desktop\sign.png" 
$bmp = new-object System.Drawing.Bitmap 600,200

$font = new-object System.Drawing.Font Consolas,18
$brushBg = [System.Drawing.Brushes]::White 
$brushFg = [System.Drawing.Brushes]::Black 
$graphics = [System.Drawing.Graphics]::FromImage($bmp) 
# 初始化从右到左的文本排版格式
$rtlFormat = [System.Drawing.StringFormat]::new([System.Drawing.StringFormatFlags]::DirectionRightToLeft)
$graphics.FillRectangle($brushBg,0,0,$bmp.Width,$bmp.Height) 
# 此处传入的X轴坐标为文本块的右侧边缘坐标,可根据排版需求自行调整数值
$graphics.DrawString($uname,$font,$brushFg,580,10, $rtlFormat)
$graphics.DrawString($job,$font,$brushFg,580,100, $rtlFormat)
$graphics.Dispose() 
$bmp.Save($filename) 

Invoke-Item $filename

注意事项

  • 启用DirectionRightToLeft参数后,DrawString方法传入的X轴坐标不再是文本左侧起始位,而是文本块的右侧边缘坐标,上面示例里设置的580是接近画布右边缘的位置,可根据实际排版需求调整。
  • 建议更换为原生支持希伯来语字符的字体,Consolas对希伯来语字符覆盖不全,可能会出现缺字、显示异常的问题。

内容的提问来源于stack exchange,提问作者Saar Kaplanski

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 18:06:07