2014-04-02 35 views
1

我有一个程序收集随时间变化的数据。我用Gtk3编写的程序实时显示数据。在“渲染”功能中,数据在离屏幕表面上绘制,然后在曝光事件中复制到绘图区域表面。Gtk移动表面变得模糊

这保留了以前的渲染操作的表面,我想要做的是将图像向左移动一个步长,然后在右侧绘制新数据。净效应应该是一个向左滚动的图像,新数据出现在右边缘。

我到目前为止的尝试一直是创建一个新的曲面,使用旧曲面作为新曲面的来源,然后使用一个班次对其进行绘制,然后使用类似的几个命令将新曲面绘制回原始,然后添加新的数据。

它有点作品,但图像变得更模糊,因为它向左移动,背景白色消失。

有没有办法让它保持清晰并实现我想要实现的目标?

顺便说一句,我正在开发GNU/Linux,但该程序确实也在Windows上构建和运行。

James。

 

    //Cairo context for the existing surface. 
    cr = cairo_create (xy_surface); 

    //create a similar surface to the existing surface 
    cairo_surface_t *tmp_surf = cairo_surface_create_similar(xy_surface, 
     CAIRO_CONTENT_COLOR, width-2, height); 

    //create cairo context for the new surface 
    cairo_t *tmp_cr = cairo_create (tmp_surf); 

    source_x = ((gdouble)width * N_SAMPLES/sweep_rate) - 2; 
    dest_x = 0.0; 

    //Set the drawing source for the new surface to be the old surface 
    cairo_set_source_surface (tmp_cr, xy_surface, dest_x - source_x, 0.0); 
    cairo_rectangle (tmp_cr, dest_x, 0, width - 2 - source_x, height); 
    cairo_set_operator(tmp_cr, CAIRO_OPERATOR_SOURCE); 
    cairo_fill (tmp_cr); 
    cairo_destroy(tmp_cr); 

    //clear the existing surface 
    cairo_set_source_rgb(cr, 1, 1, 1); 
    cairo_paint(cr); 

    cairo_set_operator(cr, CAIRO_OPERATOR_ATOP); 
    cairo_set_source_surface(cr, tmp_surf, 0, 0); 
    cairo_paint(cr); 

    cairo_surface_destroy(tmp_surf); 

+0

你为什么使用运算符ATOP而不是来源还是OVER?是否有透明度? (我认为ATOP等于SOURCE,相当于没有任何alpha的OVER) –

+0

绝望。我正在尝试很多不同的事情。消息来源是正确的。我还需要在使用xy_surface作为源之前绘制tmp_surf白色。 –

+0

请考虑添加屏幕截图以使其更清晰。 – unwind

回答

3

如果width不均匀你顺利拿到会得到画部分基于你的面的像素邻居的颜色表面原点,这意味着像素左右(综合报道,ROUNDDOWN)一.5值。

只需确保source_x没有小数位,即使用rint (source_x)即可。

+0

啊!你是一颗宝石。感谢堆。 –