The solution based on the idea of tdelaney. I use the standard input / output to communicate.
C#
Bitmap bitmap = new Bitmap(@"test.jpg");
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = @"c:\Python30\python.exe";
p.StartInfo.Arguments = string.Format("{0} {1}", "test.py", "");
p.StartInfo.RedirectStandardInput = true;
p.Start();
using (var memoryStream = new MemoryStream())
{
bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
var bytes = memoryStream.ToArray();
memoryStream.Seek(0, SeekOrigin.Begin);
p.StandardInput.BaseStream.Write(bytes, 0, bytes.Length);
p.StandardInput.BaseStream.Flush();
p.StandardInput.BaseStream.Close();
}
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Python :
import sys
import msvcrt
import os
msvcrt.setmode (sys.stdin.fileno(), os.O_BINARY)
bitmap = sys.stdin.buffer.read()
output = open("/tmp/testpython.jpg","wb")
output.write(bitmap)
output.close()
print("hehe")
exit(0)