2

我有一些旧版 MFC 应用程序,我想使用 Cairo 绘图引擎添加一些图表和图形。

我正在寻找一个如何让它工作的小例子。基本上,一旦我创建了一个 PNG 或 GIF 文件,我如何让它显示在 MFC CView 窗口中?

我的 google-fu 没有找到任何好的线索。

4

1 回答 1

1

从我的演示样本中,

// cairo_surface_t *surface;
// cairo_t *cr;

// surface = call_win32_surface_create_with_dib_T(CAIRO_FORMAT_ARGB32, 240, 80);
// cr = call_create_T (surface);

// call_surface_write_to_png_T (surface, "hello.png");


HDC src = call_win32_surface_get_dc_T(surface); // <--------
BitBlt(dest, 0, 0, 240, 80, src, 0,0, SRCCOPY); // <--------

假设您已经有一个表面,您可以使用上面的示例。
destHDC要渲染 cairo 表面的窗口的句柄。

更新: CView::OnDraw()

您应该为您的 CView(继承?)类实现 OnDraw() 方法。
您可以使用 pDC 指针来绘制 cairo 曲面,即:

pDC->BitBlt(0, 0, 240, 80, src, 0,0, SRCCOPY); // "HDC src" is mentioned above
于 2009-08-25T13:28:03.237 回答