wxBufferedPaintDC GetGraphicsContext返回NULL指针

时间:2012-04-10 07:21:27

标签: wxwidgets

为了消除闪烁,我使用wxBufferedPaintDC代替wxPaintDC。但是出现了问题。在我的绘图函数中,为了绘制一个三次beizer曲线,我必须使用GetGraphicsContext来创建一个路径。我的问题是为什么GetGraphicsContext在使用wxBufferedPaintDC时返回NULL指针。

void DotGraphView::OnPaint(wxPaintEvent & WXUNUSED(evt))
{
    wxBufferedPaintDC dc(this);

    PrepareDC(dc);

    PaintBackground(dc);

    wxGCDC &gdc = (wxGCDC&)dc;
    wxGraphicsContext * gc = gdc.GetGraphicsContext(); /* here gc = NULL */
    wxGraphicsPath path = gc->CreatePath(); /* program collapses here */

    ...
}

3 个答案:

答案 0 :(得分:0)

您从wxBufferedPaintDCwxGCDC的演员对我有点怀疑,wxGraphicsContext页面建议这样做:

wxGraphicsContext *gc = wxGraphicsContext::Create( dc );
if (gc)
{
    //drawing code here
    delete gc;
}

答案 1 :(得分:0)

我也感到怀疑,建议页面不起作用。 现在我使用以下代码,程序运行正常。

wxBufferedPaintDC pdc(this);

wxGCDC gdc;
wxGraphicsRenderer * const renderer = wxGraphicsRenderer::GetDefaultRenderer();
wxGraphicsContext * context = renderer->CreateContext(pdc);
gdc.SetGraphicsContext(context);

wxDC & dc = (wxDC &)gdc;
PrepareDC(dc);

Draw(dc);

...

答案 2 :(得分:0)

您应该使用wxAutoBufferedPaintDC。 没有必要在某些平台上缓冲(如GTK)。

然后,您可以使用构造函数

wxGCDC gcdc(dc);

至少在GTK和MSW上有效。

相关问题