Created
January 5, 2021 21:06
-
-
Save mcenirm/e0cbecf6eaf0bec810e6a05c88f2dfa9 to your computer and use it in GitHub Desktop.
Make an image using PowerShell and System.Drawing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -Version 2 | |
# https://stackoverflow.com/a/2068019 | |
Add-Type -AssemblyName System.Drawing | |
$filename = "$psscriptroot\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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment