Advertisement
wetyukmnbxc

Untitled

Mar 8th, 2023
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Here's a PowerShell script that uses the .NET framework to add a button as an overlay to an existing image:
  2.  
  3. powershell
  4. # Load the System.Drawing assembly
  5. Add-Type -AssemblyName System.Drawing
  6.  
  7. # Load the image
  8. $image = [System.Drawing.Image]::FromFile("C:\path\to\image.jpg")
  9.  
  10. # Create a new bitmap with the same dimensions as the image
  11. $bitmap = New-Object System.Drawing.Bitmap $image.Width, $image.Height
  12.  
  13. # Create a graphics object from the bitmap
  14. $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
  15.  
  16. # Draw the image onto the bitmap
  17. $graphics.DrawImage($image, 0, 0)
  18.  
  19. # Create a button object
  20. $button = New-Object System.Windows.Forms.Button
  21. $button.Text = "Click me!"
  22. $button.Width = 100
  23. $button.Height = 30
  24.  
  25. # Set the button's location on the image
  26. $buttonLocation = New-Object System.Drawing.Point(50, 50)
  27. $button.Location = $buttonLocation
  28.  
  29. # Draw the button onto the bitmap
  30. $button.DrawToBitmap($bitmap, $button.Bounds)
  31.  
  32. # Save the modified image
  33. $bitmap.Save("C:\path\to\modified_image.jpg")
  34.  
  35. # Clean up
  36. $image.Dispose()
  37. $bitmap.Dispose()
  38. $graphics.Dispose()
  39. $button.Dispose()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement