我可以在不对批处理文件使用任何转换工具的情况下将 jpg 更改为 bmp 吗?检查此链接后
看来我不能。
如果混合批处理/JScript.Net 文件是一个选项,你可以执行以下操作
@if (@this)==(@isBatch) @end /* ------------------------------------------------
@echo off
setlocal enableextensions disabledelayedexpansion
rem Retrieve input parameters
set "inputFile=" & for %%a in ("%~f1") do if /i "%%~xa"==".jpg" set "inputFile=%%~fa"
set "outputFile=" & for %%a in ("%~f2") do if /i "%%~xa"==".bmp" set "outputFile=%%~fa"
rem Check input parameters
if not defined inputFile goto :usage
if not defined outputFile goto :usage
if not exist "%inputFile%" (
echo Input file not found
exit /b 2
)
rem Search JScript.Net compiler
set "jsc=" & for /f "delims=" %%a in ('
dir /b /s /a-d "%SystemRoot%Microsoft.NETFramework*jsc.exe"
') do set "jsc=%%a"
if not defined jsc (
echo JScript.Net compiler not found
exit /b 3
)
rem Start hybrid to exe conversion
call :launchConversion
exit /b %errorlevel%
:launchConversion
rem Try to compile current batch file JScript part
for %%t in ("%temp%%~nx0.%random%%random%%random%%random%.exe") do (
rem If there is a collision, try again
if exist "%%~ft" goto :launchConversion
rem Try to compile and execute conversion
"%jsc%" /nologo /out:"%%~ft" "%~f0" && "%%~ft"
rem Remove exe file
) & 2>nul del /q "%%~ft"
rem Done
endlocal & exit /b %errorlevel%
:showUsage
echo Usage: %~n0 inputFile outputFile
echo(
exit /b 1
*/ //---------------------------------------------------------------------------
// JScript.Net part
import System;
import System.Drawing;
// Simply read input jpg file and save output bmp file
Image.FromFile(
System.Environment.GetEnvironmentVariable("inputFile")
).Save(
System.Environment.GetEnvironmentVariable("outputFile")
, System.Drawing.Imaging.ImageFormat.Bmp
)