开发者

Can I "draw"/create an image with a given text with powershell?

I just wondered if it would be开发者_JAVA百科 possible to create a small, simple jpg, png, gif with a given Text in powershell:

e.g: a small square, 250px × 61px, yellow background and black text on it: "Test"

Can I do this with "System.Drawing.Image"?

Thanks


Sure, if you're on PowerShell 2.0 try this:

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  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜