如何绘制从glReadPixels捕获的屏幕截图到wxWidgets对话框/面板

How to draw screenshot captured from glReadPixels to wxWidgets dialog/panel

本文关键字:屏幕截图 wxWidgets 对话框 面板 何绘制 绘制 glReadPixels      更新时间:2023-10-16

我有一个OpenGL窗口和一个wxWidget对话框。我想把OpenGL镜像到对话框。所以我要做的是:

  1. 捕获opengl的截图
  2. 显示在wxwidgets对话框中。

任何想法?

更新:这就是我目前如何使用glReadPixels(我也暂时使用FreeImage保存到BMP文件,但我希望文件保存被删除,如果有办法直接通道到wxImage)

// Make the BYTE array, factor of 3 because it's RBG.
BYTE* pixels = new BYTE[ 3 * width * height];
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
// Convert to FreeImage format & save to file
FIBITMAP* image = FreeImage_ConvertFromRawBits(pixels, width, height, 3 * width, 24, 0x0000FF, 0xFF0000, 0x00FF00, false);
FreeImage_Save(FIF_BMP, image, "C:/test.bmp", 0);
// Free memory
delete image;
delete pixels;
  // Add Image Support for all types
  wxInitAllImageHandlers();  
  BYTE* pixels = new BYTE[ 3 * width * height];
  glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
  // width height pixels alpha
  wxImage img(with, height, pixels, NULL); // I am not sure if NULL is permitted on the alpha channel, but you can test that yourself :).  
 // Second method:
 wxImage img(width, heiht, true);
 img.SetData(pixels);

你现在可以使用图像显示,保存为jpg png bmp任何你喜欢的。如果只是在对话框中显示,你不需要将其保存到硬盘上,当然,你可以这样做。然后在堆上创建图像。http://docs.wxwidgets.org/stable/wx_wximage.html wximagector

希望有所帮助