2010-01-14 58 views

回答

12

當然,如果你在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 
+0

完美的作品!謝謝 – icnivad 2010-01-15 08:23:33

+0

添加類型在PS 1.0中不可用,您可以使用:[Reflection.Assembly] :: LoadWithPartialName(「System.Drawing」) – 2012-09-12 03:57:17

+0

注意:似乎創建的文件是PNG(即沒有特殊的'Save'函數中的邏輯轉換爲適合文件名的格式,而是可以傳遞第二個參數來改變文件格式:'$ bmp.Save($ filename,[System.Drawing.Imaging.ImageFormat] :: Jpeg)'。https://msdn.microsoft.com/en-us/library/system.drawing.image.save(v=vs.110).aspx – JohnLBevan 2016-03-08 19:28:45

相關問題