我有一个程序可以收集随时间变化的数据。我使用带有 Gtk3 的 C 语言编写的程序实时显示数据。在“渲染”功能中,数据在屏幕外表面上绘制,然后在公开事件中复制到绘图区域表面。
这保留了之前渲染操作的表面,我想做的是将图像向左移动一个步长,然后在右侧绘制新数据。最终效果应该是图像向左滚动,新数据出现在右边缘。
到目前为止,我的尝试是创建一个新表面,使用旧表面作为新表面的来源,并通过移动对其进行绘制,然后使用类似的几个命令将新表面绘制回原始表面,在添加新数据之前。
它有点管用,但是当它向左移动时图像变得模糊,背景白色消失。
有没有办法让它保持敏锐并实现我想要实现的目标?
顺便说一句,我正在 GNU/Linux 上开发,但该程序也可以在 Windows 上构建和运行。
詹姆斯。
//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);
最佳答案
如果 width
不均匀,您会得到表面原点的 .5
值,这意味着左右像素(向上舍入、向下舍入)将部分绘制关于表面像素邻居的颜色。
只需确保 source_x
没有小数位,即在使用前执行 rint (source_x)
。
关于c - Gtk 移动表面变得模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22802284/