Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here's a PowerShell script that uses the .NET framework to add a button as an overlay to an existing image:
- powershell
- # Load the System.Drawing assembly
- Add-Type -AssemblyName System.Drawing
- # Load the image
- $image = [System.Drawing.Image]::FromFile("C:\path\to\image.jpg")
- # Create a new bitmap with the same dimensions as the image
- $bitmap = New-Object System.Drawing.Bitmap $image.Width, $image.Height
- # Create a graphics object from the bitmap
- $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
- # Draw the image onto the bitmap
- $graphics.DrawImage($image, 0, 0)
- # Create a button object
- $button = New-Object System.Windows.Forms.Button
- $button.Text = "Click me!"
- $button.Width = 100
- $button.Height = 30
- # Set the button's location on the image
- $buttonLocation = New-Object System.Drawing.Point(50, 50)
- $button.Location = $buttonLocation
- # Draw the button onto the bitmap
- $button.DrawToBitmap($bitmap, $button.Bounds)
- # Save the modified image
- $bitmap.Save("C:\path\to\modified_image.jpg")
- # Clean up
- $image.Dispose()
- $bitmap.Dispose()
- $graphics.Dispose()
- $button.Dispose()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement