Created
May 13, 2011 02:20
-
-
Save zippy1981/969855 to your computer and use it in GitHub Desktop.
Display an image from Windows Powershell
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
# Loosely based on http://www.vistax64.com/powershell/202216-display-image-powershell.html | |
[void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms") | |
$file = (get-item 'C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg') | |
#$file = (get-item "c:\image.jpg") | |
$img = [System.Drawing.Image]::Fromfile($file); | |
# This tip from http://stackoverflow.com/questions/3358372/windows-forms-look-different-in-powershell-and-powershell-ise-why/3359274#3359274 | |
[System.Windows.Forms.Application]::EnableVisualStyles(); | |
$form = new-object Windows.Forms.Form | |
$form.Text = "Image Viewer" | |
$form.Width = $img.Size.Width; | |
$form.Height = $img.Size.Height; | |
$pictureBox = new-object Windows.Forms.PictureBox | |
$pictureBox.Width = $img.Size.Width; | |
$pictureBox.Height = $img.Size.Height; | |
$pictureBox.Image = $img; | |
$form.controls.add($pictureBox) | |
$form.Add_Shown( { $form.Activate() } ) | |
$form.ShowDialog() | |
#$form.Show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Created 11 years ago but useful to me this morning! Thanks people.