我正在嘗試制作一個簽名制作器,我想用希伯來語寫下姓名和作業,但它像英語一樣從左邊開始。有沒有辦法讓文字從右邊開始?
這是我的代碼,例如:
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
#Get the image
#$source=Get-Item
#$img = [System.Drawing.Image]::FromFile($_.FullName)
#Create a bitmap
#$bmp = new-object System.Drawing.Bitmap([int]($img.width)),([int]($img.height))
$font = new-object System.Drawing.Font Consolas,18
$brushBg = [System.Drawing.Brushes]::White
$brushFg = [System.Drawing.Brushes]::Black
$graphics = [System.Drawing.Graphics]::FromImage($bmp)
$graphics.FillRectangle($brushBg,0,0,$bmp.Width,$bmp.Height)
$graphics.DrawString($uname,$font,$brushFg,10,10)
$graphics.DrawString($job,$font,$brushFg,90,100)
$graphics.Dispose()
$bmp.Save($filename)
Invoke-Item $filename
uj5u.com熱心網友回復:
正如所評論的,該DrawString()方法有一個建構式,您可以使用它給它一個 StringFormat 物件,您可以在其中設定 RightToLeft 文本方向。
在您的代碼中嘗試:
$rtlFormat = [System.Drawing.StringFormat]::new([System.Drawing.StringFormatFlags]::DirectionRightToLeft)
$graphics.DrawString($uname, $font, $brushFg, [System.Drawing.PointF]::new(10,10), $rtlFormat)
$graphics.DrawString($job, $font, $brushFg, [System.Drawing.PointF]::new(90,100), $rtlFormat)
如果您使用的 PowerShell 版本對于[type]::new()語法來說太舊,請使用
$rtlFormat = New-Object -TypeName System.Drawing.StringFormat('DirectionRightToLeft')
$graphics.DrawString($uname, $font, $brushFg, (New-Object -TypeName System.Drawing.PointF(10,10)), $rtlFormat)
$graphics.DrawString($job, $font, $brushFg, (New-Object -TypeName System.Drawing.PointF(90,100)), $rtlFormat)
uj5u.com熱心網友回復:
$sf = [System.Drawing.StringFormat]::New()
$sf.Alignment = 'far'
$sf.LineAlignment = 'far'
$graphics.FillRectangle($brushBg,0,0,$bmp.Width,$bmp.Height)
$graphics.DrawString($uname,$font,$brushFg,500,100,$sf)
$graphics.DrawString($job,$font,$brushFg,500,200,$sf)
這就是我最后所做的 Thaks Theo
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/362654.html
