15

我只是想知道是否可以在 powershell 中使用给定的文本创建一个小的、简单的 jpg、png、gif:

eg:一个小方块,250px×61px,黄底黑字:“测试”

我可以用“System.Drawing.Image”做到这一点吗?

谢谢

4

1 回答 1

26

当然,如果您使用的是 PowerShell 2.0,请尝试以下操作:

Add-Type -AssemblyName System.Drawing

$filename = "$home\foo.png" 
$bmp = new-object System.Drawing.Bitmap 250,61 
$font = new-object System.Drawing.Font Consolas,24 
$brushBg = [System.Drawing.Brushes]::Yellow 
$brushFg = [System.Drawing.Brushes]::Black 
$graphics = [System.Drawing.Graphics]::FromImage($bmp) 
$graphics.FillRectangle($brushBg,0,0,$bmp.Width,$bmp.Height) 
$graphics.DrawString('Hello World',$font,$brushFg,10,10) 
$graphics.Dispose() 
$bmp.Save($filename) 

Invoke-Item $filename  
于 2010-01-14T22:28:03.110 回答