在Powershell中将图像转换为BMP 16位
我有一个代码可以将 jpg 文件文件夹批量转换为 BMP。
我的代码工作正常,但它被保存为 BMP 24 位。
我需要它使用 Powershell 将其转换为 BMP 16 位
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]
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 using Powershell
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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我修改了您的脚本以从 JPG 转换为 8 位 BMP:
您可以将
Format8bppIndexed
更改为 此页面I modified your script to convert from JPG to 8-bit BMP:
You can change the
Format8bppIndexed
to one of the other formats listed on this page