Search code examples
c++pixelcairogtkmm

How do I get rid of blury pixels in Gtkmm?


When I draw a picture and zoom way in, GTKmm (or Cairo I suppose) blends the pixels together to make a nice smooth image. I really hate that. It's terrible for debugging. I want to see clear crisp pixels with sharp images. I want to see nice little squares. So how do I turn off the cool blendy feature?

Here is how I paint the image.

Gdk::Cairo::set_source_pixbuf(cairoContext, tile->tileImage, tile->x, tile->y);
cairoContext->paint();

Also tried fill to see if it was any different.

Gdk::Cairo::set_source_pixbuf(cairoContext, tile->tileImage, tile->x, tile->y);
cairoContext->rectangle(tile->x, tile->y, tile->tileImage->get_width(), tile->tileImage->get_height());
cairoContext->fill();

It wasn't.

Edit: This doesn't work:

cairoContext->set_antialias(Cairo::Antialias::ANTIALIAS_NONE);

Solution

  • You need to set a NEAREST filter on the pattern. I'm not sure about the C++ API for this, but in C I would do the following (after the call to set_source_pixbuf):

    cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST);