pixbuf outermost pixels are white



Hi,

I found somewhere on web how to draw custom data images into a widget using
Pixbuf.  It basically works.

Unfortunately the image always has the outermost source pixels mixed with
white border.  I want the whole window to be just blue but it is not:
        http://www.jankratochvil.net/t/pixbuf.png
        Fedora 19 x86_64: gtk3-3.8.2-2.fc19.x86_64 gtkmm30-3.8.1-1.fc19.x86_64

Sorry for gtkmm, I can no longer write non-C++ GTK code.  But I think the
problem is not specific to the gtkmm C++ wrapping.


Thanks for an advice,
Jan Kratochvil


/*
g++ -o 1 1.C -Wall -Werror -std=gnu++11 -g $(pkg-config --cflags --libs gtkmm-3.0);./1
*/
#include <gdkmm/general.h>
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <gtkmm/drawingarea.h>
#include <vector>
#include <stdio.h>
using namespace std;

class Area:public Gtk::DrawingArea {
  bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) {
//    cr->translate(+0.5,+0.5);
    class RGB {
    public:
      guint8 r=0,g=0,b=0;
    };
    vector<RGB> data24;
    RGB rgb;
    rgb.b=255;
    rgb.g=rgb.r=0;
    data24.push_back(rgb);
    Glib::RefPtr<Gdk::Pixbuf> pixbuf;
    pixbuf=Gdk::Pixbuf::create_from_data((const guint8 
*)data24.data(),Gdk::COLORSPACE_RGB,false/*has_alpha*/,8/*bits_per_sample*/,
      1 /*width*/,
      1 /*height*/,
      1*3/*rowstride==width*/);
//    cr->set_identity_matrix();
    {
      cr->save();
      // Does not work: cr->set_antialias(Cairo::ANTIALIAS_NONE);
      // Does not work: cr->set_fill_rule(Cairo::FILL_RULE_EVEN_ODD);
      cr->scale(double(get_allocation().get_width ())/pixbuf->get_width (),
                double(get_allocation().get_height())/pixbuf->get_height());
      Gdk::Cairo::set_source_pixbuf(cr,pixbuf);
      cr->rectangle(0,0,pixbuf->get_width(),pixbuf->get_height());
      cr->fill();
      cr->restore();
    }
    return true;
  }
};

int main() {
  Gtk::Main *app=new Gtk::Main();
  Gtk::Window *win=new Gtk::Window();
  win->set_default_size(500,500);
  win->maximize();
  win->add(*new Area());
  win->show_all();
  app->run(*win);
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]