Cairo 可以直接在 Gtk.Pixbuf 上绘图吗?
我有一个很好的 C# 工作系统,可以在渲染方法中使用 Cairo 命令进行绘制。然而,有时我想绘制成像素图,而不是在屏幕需要更新时动态绘制。例如,目前我有:
public override void render(Cairo.Context g) {
g.Save();
g.Translate(x, y);
g.Rotate(_rotation);
g.Scale(_scaleFactor, _scaleFactor);
g.Scale(1.0, ((double)_yRadius)/((double)_xRadius));
g.LineWidth = border;
g.Arc(x1, y2, _xRadius, 0.0, 2.0 * Math.PI);
g.ClosePath();
}
但如果我选择,我希望将 Cairo 命令渲染到 Gtk.Pixbuf。比如:
g = GetContextFromPixbuf(pixbuf);
render(g);
这可能吗?如果我不必将上下文转回 pixbuf,但 cairo 绘图将直接转到 pixbuf,那就太好了。任何有关此的提示将不胜感激!
I have a fine, working system in C# that draws with Cairo commands in a render method. However, sometimes I would like to draw into a pixmap, rather than dynamically when the screen needs to be updated. For example, currently I have:
public override void render(Cairo.Context g) {
g.Save();
g.Translate(x, y);
g.Rotate(_rotation);
g.Scale(_scaleFactor, _scaleFactor);
g.Scale(1.0, ((double)_yRadius)/((double)_xRadius));
g.LineWidth = border;
g.Arc(x1, y2, _xRadius, 0.0, 2.0 * Math.PI);
g.ClosePath();
}
But I would like, if I choose, to render the Cairo commands to a Gtk.Pixbuf. Something like:
g = GetContextFromPixbuf(pixbuf);
render(g);
Is that possible? It would be great if I didn't have to turn the context back into a pixbuf, but that the cairo drawing would go directly to the pixbuf. Any hints on this would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案实际上非常简单:渲染对象时,将它们渲染到从保存的表面创建的上下文中。然后,当您渲染窗口时,插入基于相同保存表面的上下文。
创建表面:
将形状渲染到表面:
渲染窗口:
就是这样!
The answer is actually quite easy: when you render the objects, render them to a context created from a saved surface. Then when you render the window, insert a context based on the same saved surface.
Create a surface:
Render a shape to the surface:
Render the window:
That's it!