0

I have the following code to draw on a Pixbuf:

private Pixbuf drawOnPixbuf(Pixbuf original)
{
    Surface surface = new ImageSurface(Format.Argb32, original.Width, original.Height);
    Context ctx = new Context(surface);
    CairoHelper.SetSourcePixbuf(ctx, original, 0, 0);

    // Draw on the surface here. Not shown since not relevant. 

    // Here, I want to convert the surface back to pixbuf.
    Pixbuf finishedPixbuf = ...;

    ctx.GetTarget().Dispose();
    ctx.Dispose();

    return finishedPixbuf;
}

I can't find out how to convert the Surface back to Pixbuf.

Bobface
  • 2,782
  • 4
  • 24
  • 61

1 Answers1

0

The function you are looking for seems to be part of Gdk:

cairo_surface_t *
gdk_cairo_surface_create_from_pixbuf (const GdkPixbuf *pixbuf,
                                      int scale,
                                      GdkWindow *for_window);

https://developer.gnome.org/gdk3/stable/gdk3-Cairo-Interaction.html#gdk-cairo-surface-create-from-pixbuf

Specifically, gdk_cairo_surface_create_from_pixbuf(pixbuf, 1, NULL) should do what you want. (Sorry, I do not know how to express this in C#.)

Uli Schlachter
  • 9,337
  • 1
  • 23
  • 39