作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 C++ 中使用 gtkmm 作为 GUI。我有一个 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;
}
我想要一个改变图像的函数(使用 filename2)。但我找不到如何:-/
有人可以帮我解决这个问题吗?谢谢你
最佳答案
作为类(class)成员:
void change_image(string filename2)
{
m_image = Gdk::Pixbuf::create_from_file(filename2.c_str());
queue_draw();
}
关于c++ - 在 C++ gtk::drawarea 中:如何刷新图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14812580/
我的目的(用于个人练习)是创建一个平面笛卡尔,其中我代表一些数学函数。因此我需要交易坐标,如何在 DrawArea 上添加文本?我搜索过,但没有找到任何关于使用 gtk3-C 绘制文本的内容(示例 e
我正在尝试在 Gtk.DrawArea 内获取鼠标轮事件。有人知道如何实现这一目标吗?方法当前从未调用 DrawTest.on_scroll(): #!/usr/bin/env python3
我在 C++ 中使用 gtkmm 作为 GUI。我有一个 Gtk::DrawingArea,上面有一张图片(文件名): class MyArea : public Gtk::DrawingArea {
我是一名优秀的程序员,十分优秀!