Powershell convert image to BMP 16 bits

Luis M. Cova 1 Reputation point
2022-02-22T16:23:14.667+00:00

I have a code to batch convert a folder of jpg files to BMP.
The code i have works ok, But it gets saved as BMP 24 bits..
I need it to convert it to BMP 16 bits

function ConvertImage{
$Origen="C:\jpg" #path to files
$Destino="C:\bmp" #path to files

if (Test-Path $Origen){

Load required assemblies and get object reference

[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
foreach($file in (Get-ChildItem -Path "$Origen\*.jpg" -Exclude *-*)){
    $convertfile = new-object System.Drawing.Bitmap($file.Fullname)
    $newfilname = $Destino + '\' + $file.BaseName + '.bmp'
    $convertfile.Save($newfilname, "bmp")
    $file.Fullname
}  

}
else{
Write-Host "Path not found."
}
};ConvertImage -path $args[0]

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,504 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 46,476 Reputation points
    2022-02-22T19:19:17.117+00:00

    You need to define the format using the PixelFormat system.drawing.imaging.pixelformat

    Here's an example: how-to-save-a-bitmap-object-in-16bit

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.