Powershell and GDI RRS feed

  • Question

  • Hi 

    Using Powershell to make graphics can be quite powerfull. 

    I also think there is a way to include an existing BMP file in a new one you are building.

    I've made a small example that is boiled down to below:

    Add-Type -AssemblyName System.Drawing
    $filename ="$home\test.png"
    $bmp = new-object System.Drawing.Bitmap 1240,800
    $graphics = [System.Drawing.Graphics]::FromImage($bmp)
    $font = new-object System.Drawing.Font Consolas,24
    $brushBg = [System.Drawing.Brushes]::White

    $font = new-object System.Drawing.Font SIMPLEX ,8.8
    $brushFg = [System.Drawing.Brushes]::BLACK
    $graphics.DrawString('This is a text string',$font, $brushFg,5 ,50 )

    $Toinsert = "$home\foo.png" 


    Invoke-Item $filename 

    My problem is that the DrawImage command comes out with an anoying error on the FromFile. 

    Anyone who can point out what should be changed?



    Tuesday, February 12, 2013 2:59 PM


  • Try to replace it with

    $Toinsert = New-Object System.Drawing.Bitmap "$home\foo.png"


    Best Regards
    Claus Codam
    Consultant, Developer
    Coretech - Blog

    • Edited by Claus Codam Tuesday, February 12, 2013 3:35 PM script error
    • Marked as answer by Thomas Lee Tuesday, February 12, 2013 7:55 PM
    Tuesday, February 12, 2013 3:34 PM