winutil/functions/private/convertTo-Bitmap.ps1
MyDrift c2c2e5ea71 rework
- add overlay presets
- rework image saving & converting
- removed popup after uninstalling applications
2024-07-14 21:30:11 +02:00

31 lines
873 B
PowerShell

function ConvertTo-Bitmap {
<#
.SYNOPSIS
Converts an image file to a Bitmap object
.PARAMETER image
The path to the image file to convert
.EXAMPLE
ConvertTo-Bitmap -image "C:\path\to\image.png"
#>
param (
$image
)
# Read the image file as a byte array
$imageBytes = [System.IO.File]::ReadAllBytes($image)
# Convert the byte array to a Base64 string
$base64String = [System.Convert]::ToBase64String($imageBytes)
# Create a streaming image by streaming the base64 string to a bitmap streamsource
$bitmap = New-Object System.Windows.Media.Imaging.BitmapImage
$bitmap.BeginInit()
$bitmap.StreamSource = [System.IO.MemoryStream][System.Convert]::FromBase64String($base64String)
$bitmap.EndInit()
$bitmap.Freeze()
# Return the bitmap object
return $bitmap
}