drawing bitmap with transparency



Hi
In my previous posting i had run off in a bad direction...
After lots of googling and RTFM i found a solution that seems to work for me:
Use the Cairo Context of a DrawingArea (by means of he on_draw() callback)
to first draw the background and then use
  Gdk::Cairo::set_source_pixbuf()
to draw the pixbuf containing the image with transparency into the context.
(basically i combined the two examples of the Gnome book "programming
with gtkmm3":
"Drawing Area - Lines" and "Drawing Area - Image")

bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) {
    Gtk::Allocation allocation = get_allocation();
    const int width = allocation.get_width();
    const int height = allocation.get_height();

    cr->save();
    cr->scale(width, height);

    cr->set_line_width(0.05);
    // do some cairo drawing for the background
    // this may also involve drawing an image to the cntext
    // ...
    cr->restore();
    // draw the image to the context
    Gdk::Cairo::set_source_pixbuf(cr, m_image,
                                  (width - m_image->get_width())/2,
(height - m_image->get_height())/2);
    cr->paint();
    return true;
}


Sorry for my unnecessary cry for help


Jody


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