使用ImageMagick与C ++系统调用

时间:2013-06-19 00:39:46

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

在我的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 display命令。我怎么能这样做?

1 个答案:

答案 0 :(得分:2)

我想这更像是字符串连接?

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());
    }
}