Skip to content

Instantly share code, notes, and snippets.

@wsmelton
Created March 20, 2020 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wsmelton/0a27ec1aa9127ca23ff1b7772ec143c9 to your computer and use it in GitHub Desktop.
Save wsmelton/0a27ec1aa9127ca23ff1b7772ec143c9 to your computer and use it in GitHub Desktop.
Trying to add text to a give bmp image file
#Ref: https://stackoverflow.com/a/6827017/12974596
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms");
$file = Get-ChildItem 'C:\temp\template.bmp'
$img = New-Object System.Drawing.BitMap($file.FullName)
$newFile = 'C:\temp\eureka.bmp'
[String]$drawString = "lab-ss-01 server"
$colorBlue = (New-Object System.Drawing.ColorConverter).ConvertFromString("blue")
$drawFont = New-Object -TypeName System.Drawing.Font -ArgumentList "Arial",16
$drawBrush = New-Object -TypeName System.Drawing.SolidBrush -ArgumentList $colorBlue
[float]$x = '150.0'
[float]$y = '50.0'
$stringFlags = New-Object System.Drawing.StringFormatFlags
$stringFlags.value__ = 2
$drawFormat = New-Object -TypeName System.Drawing.StringFormat
$drawFormat.FormatFlags = $stringFlags
# this line won't run
(New-Object -TypeName System.Drawing.Graphics).DrawString($drawString,$drawFont,$drawBrush,$x,$y,$drawFormat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment