1

C++ の GUI に gtkmm を使用しています。私はGtk::DrawingArea画像(ファイル名)を持っています:

class MyArea : public Gtk::DrawingArea
{
public:
    MyArea(string filename)
    {
        m_image = Gdk::Pixbuf::create_from_file(filename.c_str());
    }

    virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
    {
        if (!m_image)
            return false;

        Gtk::Allocation allocation = get_allocation();
        const int width  = allocation.get_width();
        const int height = allocation.get_height();

        // Draw the image in the middle of the drawing area, or (if the image is
        // larger than the drawing area) draw the middle part of the image.
        Gdk::Cairo::set_source_pixbuf(cr, m_image, (width - m_image->get_width())/2, (height - m_image->get_height())/2);
        cr->paint();

        return true;
    }
    Glib::RefPtr<Gdk::Pixbuf> m_image;
}

画像を変更する機能が欲しいです(ファイル名2で)。しかし、私は方法を見つけることができません:-/

誰かがこれを手伝ってくれませんか。ありがとうございました

4

1 に答える 1

3

クラスのメンバーとして:

void change_image(string filename2)
{
    m_image = Gdk::Pixbuf::create_from_file(filename2.c_str());
    queue_draw();
}
于 2013-02-11T13:09:00.957 に答える