PicList/public/windows.ps1

27 lines
682 B
PowerShell
Raw Normal View History

2019-09-10 02:38:08 -04:00
param($imagePath)
2019-09-10 02:38:08 -04:00
# Adapted from https://github.com/octan3/img-clipboard-dump/blob/master/dump-clipboard-png.ps1
Add-Type -Assembly PresentationCore
2019-09-10 02:38:08 -04:00
$img = [Windows.Clipboard]::GetImage()
2019-09-10 02:38:08 -04:00
if ($img -eq $null) {
"no image"
Exit 1
}
2019-09-10 02:38:08 -04:00
if (-not $imagePath) {
"no image"
Exit 1
}
2019-09-10 02:38:08 -04:00
$fcb = new-object Windows.Media.Imaging.FormatConvertedBitmap($img, [Windows.Media.PixelFormats]::Rgb24, $null, 0)
$stream = [IO.File]::Open($imagePath, "OpenOrCreate")
$encoder = New-Object Windows.Media.Imaging.PngBitmapEncoder
$encoder.Frames.Add([Windows.Media.Imaging.BitmapFrame]::Create($fcb)) | out-null
$encoder.Save($stream) | out-null
$stream.Dispose() | out-null
$imagePath