输出图像字符串C++到C#父程序(不保存到硬盘)

Output image string C++ to C# parent program (not saving to HDD)

我有一个处理图像的 C++ 应用程序 (.Exe)。 它以一张图片 IN 作为参数并自动保存一张新图片作为输出。

我想要 运行 我的 C# 应用程序,它将 运行 带有字符串参数的 .exe 应用程序,而不是必须读取 HDD 上的图像我希望 C++ 应用程序 return 立即将字符串或其他内容发送给父 C# 应用程序,以便在保存到硬盘之前再次处理它。

我有 C++ 源代码。所以我现在可以修改它的输出:

unsigned char *pixels = new unsigned char[width * height * 3];
unsigned char *p = pixels, *b = bitmap;
int col, row;

for (row = 0; row < height; row++)
for (col = 0; col < width; col++)
{
    *p++ = *b;
    *p++ = *b;
    *p++ = *b++;
}

corona::Image *img = corona::CreateImage(width, height, IMAGE_FORMAT, pixels);
corona::SaveImage(filename, corona::FF_AUTODETECT, img);
delete img;

那么,该 C++ 应用程序中的新代码是什么? 我的 C# 主父应用程序中的代码是 运行 并返回要处理的输出? 谢谢大家

编辑: 对于 C# 部分(运行 C++ .exe 并取回输出),我想我在 Whosebug 上找到了解决方案:How to hide cmd window while running a batch file?

仍然需要 C++ 部分,因为我对 C++ 完全一无所知。

您可以选择以下两种方式之一

  1. 创建 named shared memory in the C# application, pass the name of this shared memory to the C++ application. The C++ application then writes its results to this shared memory,它可以在写入最终文件之前由 C# 应用程序处理。
  2. 编写Base64 encoded data from the C++ app to stdout (using printf or cout) and read that in from the parent C# application, decode并处理。

请注意,选项 1 将比选项 2 快得多