Skip to content

Instantly share code, notes, and snippets.

@omarrodriguez15
Created July 30, 2022 13:53
Show Gist options
  • Select an option

  • Save omarrodriguez15/ab77871e196c7769f00134305850f19e to your computer and use it in GitHub Desktop.

Select an option

Save omarrodriguez15/ab77871e196c7769f00134305850f19e to your computer and use it in GitHub Desktop.
Display a image full screen with a background gradient. (Purposefully include bug in this version for blog)
Add-Type -AssemblyName "System.Windows.Forms"
Add-Type -AssemblyName "System.Drawing"
$fileBytes = Get-Content -Encoding Byte 'C:\Users\rodri\Downloads\foo.jpg'
# $fileBytes = [Convert]::FromBase64String($fileContent)
$fileMemoryStream = [System.IO.MemoryStream]::new($fileBytes)
$imageStream = [System.Drawing.Image]::FromStream($fileMemoryStream)
[System.Windows.Forms.Application]::EnableVisualStyles()
$form = New-Object Windows.Forms.Form
$form.TopMost = $true
$form.WindowState = [System.Windows.Forms.FormWindowState]::Maximized
$pictureBox = New-Object Windows.Forms.PictureBox
$pictureBox.Dock = [System.Windows.Forms.DockStyle]::Fill
$pictureBox.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::CenterImage
$pictureBox.Image = $imageStream
$form.add_paint({
$back = [System.Drawing.Bitmap]::new($pictureBox.Width, $pictureBox.Height)
$myBrush = [System.Drawing.Drawing2D.LinearGradientBrush]::new(
[System.Drawing.Point]::new(0, 10),
[System.Drawing.Point]::new($pictureBox.Width, 10),
[System.Drawing.Color]::FromArgb(166, 206, 57),
[System.Drawing.Color]::FromArgb(49, 169, 224)
)
$graphics = [System.Drawing.Graphics]::FromImage($back)
$graphics.FillRectangle($myBrush, $pictureBox.DisplayRectangle)
$pictureBox.BackgroundImage = $back
})
$form.controls.add($pictureBox)
[System.Windows.Forms.Application]::Run($form)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment