cairomm绘制单个像素

时间:2014-08-12 11:59:25

标签: c++ cairo

我有一个简单的布尔矩阵我希望将其视为图像。我正在使用Cairomm。在文档中,我看到如何绘制直线,曲线,弧线。但我只是想为每个像素添加黑白颜色。没有关于像素访问的任何文档。这是我从例子中复制的内容。虽然我想要一个单色图像。不是FORMAT_ARGB32

  Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, matrix.cols(), matrix.rows());
  Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create(surface);

现在我正在绘制1像素线

  context->set_antialias(Cairo::ANTIALIAS_NONE);

  context->save(); // save the state of the context
  context->set_source_rgb(1.0, 1.0, 1.0);
  context->paint(); // fill image with the color
  context->restore(); // color is back to black now

  context->set_source_rgb(0.0, 0.0, 0.0);
  context->set_line_width(1.0);
  context->move_to(1.0, 1.0);
  context->line_to(2.0, 2.0);
  context->stroke();

这是否可以,或者有类似context->draw(row, col, color)的内容?

1 个答案:

答案 0 :(得分:0)

ImageSurface有一个get_data()方法。与flush()(直接修改数据之前)和mark_dirty()(之后)一起使用,可以使用它直接修改像素数据并设置单个像素。

http://cairographics.org/documentation/cairomm/reference/classCairo_1_1ImageSurface.html#a94ba52fe4a201579c8a5541717822bdb

相关问题