【问题标题】:using ImageMagick with C++ system call使用带有 C++ 系统调用的 ImageMagick
【发布时间】:2013-06-19 13:22:17
【问题描述】:

在我的 C++ 程序中,我可以通过系统调用使用 ImageMagick 命令。例如,要显示一个名为 button_out.miff 的图像,我可以在我的程序中放入以下代码:

system("display button_out.miff -display :0");

现在我想将图像文件名“button_out.miff”作为参数传递给我的 c++ 程序。例如,如果我编译的程序名为test.exe,我希望在我运行命令时:

test.exe button_out.miff

我的程序可以将 button_out.miff 作为参数传递给 ImageMagick 显示命令。我怎么能这样做?

【问题讨论】:

    标签: c++ imagemagick command-line-arguments


    【解决方案1】:

    我猜这更多的是关于字符串连接?

    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        if (argc > 1)
        {
            string filename = CW2AEX<>(argv[1]);
    
            stringstream ss;
            ss << "display " << filename << "-display :0";
    
            system(ss.str().c_str());
        }
    }
    

    【讨论】:

    • 你可以用同样的方法给你的字符串添加任何其他参数,我看不出有什么区别。
    猜你喜欢
    • 2016-02-09
    • 1970-01-01
    • 1970-01-01
    • 2013-09-10
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多