从嵌入式解释器捕获 python 窗口输出C++
Capturing python windowed output from C++ embedded interpreter
我正在使用boost python在C++应用程序中嵌入python解释器。 (pybind11 也可以(
如果我从嵌入式解释器调用 matplotlib,如下所示:
import matplotlib.pyplot as plt
import numpy as np
plt.plot([1,2,3,4],[1,4,9,16])
plt.show()
python 解释器打开一个新窗口(与我的应用程序的主窗口分开(以显示 matplotlib 图。
我知道这是一个很长的镜头,但有什么办法可以拦截它吗? 我希望能够捕获此单独窗口中显示的像素,并在应用程序主窗口的图形上下文中显示它们。
我猜这是不可能的,因为我相信窗口是如何生成的。 但想检查是否有人对此有任何见解。
您可以使用 matplotlib 的硬拷贝后端之一,并将画布的像素保存到可以导出到C++上下文的字符串中。以下是蟒蛇代码:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot
fig = matplotlib.pyplot.figure()
ax = fig.add_subplot ( 111 )
ax.plot([1,2,3,4],[1,4,9,16])
fig.canvas.draw ()
w,h = fig.canvas.get_width_height() # width and height of the canvas
buf = fig.canvas.tostring_argb() # a byte string of type uint8
在C++代码中,可以使用变量w
、h
和buf
在主窗口中显示图形。
相关文章:
- 如何从 Win32 C++ 应用程序输出到父控制台窗口?
- 为什么输出窗口上没有显示输出?
- 从嵌入式解释器捕获 python 窗口输出C++
- 为什么 string::begin() 在即时窗口中输出整个字符串
- 输出窗口中消息的可视化工作室源
- 输出 c++ 窗口 wstring 日志在终端中正确
- C++/Visual Studio-如何输出到测试输出窗口
- 如何在C++中居中输出控制台窗口
- 为什么如果我从键盘输入EOF克里昂不要在运行窗口打印程序的输出?
- C++:显示控制台窗口的输出
- 如何将日志记录写入Visual Studio输出窗口?
- 输入层类型:图像数据在窗口咖啡cpp中给出空白输出
- 无法在 Bash 中为窗口传输输出
- 调整项目在Visual Studio的输出窗口中构建报告
- 具有控制台输出且没有新窗口的 Win32 应用程序
- 使用分叉时的输出窗口
- C++输出信息到新窗口
- 窗口上的输出格式
- 带有SDL的C++CMD窗口输出
- 有没有办法让窗口输出 ansi 转义序列