jpg到bmp没有转换工具

时间:2017-06-30 15:23:49

标签: batch-file

我可以在不使用批处理文件上的任何转换工具的情况下将jpg更改为bmp吗?检查此link

看起来我不能。

1 个答案:

答案 0 :(得分:1)

如果可以选择混合批处理/ 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.NET\Framework\*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
    )