首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >启动Windows10 Paint3D以打开特定的镜像文件

启动Windows10 Paint3D以打开特定的镜像文件
EN

Stack Overflow用户
提问于 2020-04-25 03:31:09
回答 2查看 849关注 0票数 1

我希望启动Windows10Store应用程序Paint3D并使其打开一个JPG镜像。我将使用Java,但很高兴看到CMD / C# / Windows API回答。这不是关于如何使用ProcessBuilder的问题。

与标准的MS Paint应用程序不同,Paint3D来自Windows Store,没有Windows可执行文件或别名。Paint3D确实支持启动url协议ms-paint:,它可以在web浏览器中使用,也可以作为start ms-paint:从Windows CMD.EXE启动。

这段代码展示了我尝试启动Paint3D的两种方式,一种是正确打开Paint3D,但使用的是mspaint.exe;另一种是打开Paint3D,但没有图像。

有没有人知道是否可以在不通过mspaint.exe启动的情况下运行Paint3D来打开JPG?

代码语言:javascript
复制
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;

public class LaunchPaint3D
{
    public static void exec(String[] cmd) throws InterruptedException, IOException
    {
        System.out.println("exec "+Arrays.toString(cmd));

        Path tmpdir = Path.of(System.getProperty("java.io.tmpdir"));
        ProcessBuilder pb = new ProcessBuilder(cmd);

        Path out = tmpdir.resolve(cmd[0]+"-stdout.log");
        Path err = tmpdir.resolve(cmd[0]+"-stderr.log");
        pb.redirectError(out.toFile());
        pb.redirectOutput(err.toFile());

        Process p = pb.start();
        int rc = p.waitFor();

        System.out.println("Exit "+rc +' '+(rc == 0 ? "OK":"**** ERROR ****")
                          +" STDOUT \""+Files.readString(out)+'"'
                          +" STDERR \""+Files.readString(err)+'"');
        System.out.println();
    }

    public static void main(String[] args) throws InterruptedException, IOException
    {
        var jpg = Path.of(args[0]).toAbsolutePath();

        System.out.println("Open "+jpg+" isRegularFile="+Files.isRegularFile(jpg));

        String[] cmdA = new String[] {"mspaint.exe", jpg.toString()+" /ForceBootstrapPaint3D"};
        String[] cmdB = new String[] {"cmd", "/c", "start", "ms-paint:", jpg.toString()};
        // Also tried String[] cmdB = new String[] {"cmd", "/c", "start", "ms-paint:"+jpg.toString()};

        System.out.println("Open Paint3D using MS-PAINT.EXE");
        exec(cmdA);

        System.out.println("PRESS RETURN");
        System.in.read();

        System.out.println("Open Paint3D using URL-PROTOCOL");
        exec(cmdB);

        System.out.println("END");
    }
}

上面的示例测试运行:

代码语言:javascript
复制
Open c:\temp\small.jpg isRegularFile=true
Open Paint3D using MS-PAINT.EXE
exec [mspaint.exe, c:\temp\small.jpg /ForceBootstrapPaint3D]
Exit 0 OK STDOUT "" STDERR ""

PRESS RETURN

Open Paint3D using URL-PROTOCOL
exec [cmd, /c, start, ms-paint:, c:\temp\small.jpg]
Exit 0 OK STDOUT "" STDERR ""

END
EN

回答 2

Stack Overflow用户

发布于 2020-04-26 23:27:12

我找到了一个使用旧的Paint应用程序的solution,它支持使用传递的文件参数启动来绘制3D。Windows注册表还显示,此机制在Windows中用于编辑各种图像文件类型,如JPG:

代码语言:javascript
复制
Computer\HKEY_CLASSES_ROOT\SystemFileAssociations\.jpg\Shell\3D Edit\command
=>
%SystemRoot%\system32\mspaint.exe "%1" /ForceBootstrapPaint3D

从CMD.EXE运行:

代码语言:javascript
复制
mspaint "C:\TEMP\A.jpg" /ForceBootstrapPaint3D

Java的等价物:

代码语言:javascript
复制
new ProcessBuilder("mspaint.exe", "c:\\TEMP\\A.jpg /ForceBootstrapPaint3D" ).start()
票数 1
EN

Stack Overflow用户

发布于 2020-04-25 03:41:50

您应该显示不起作用的源代码。我假设您忘记了反斜杠字符引入了转义序列。用双反斜杠\\/替换它们。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61416086

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档