public static Surface CreateSurfaceForPixbuf (Cairo.Context cr, Gdk.Pixbuf pixbuf) { Surface surface = cr.GetTarget ().CreateSimilar (cr.GetTarget ().Content, pixbuf.Width, pixbuf.Height); Cairo.Context surface_cr = new Context (surface); Gdk.CairoHelper.SetSourcePixbuf (surface_cr, pixbuf, 0, 0); surface_cr.Paint (); ((IDisposable)surface_cr).Dispose (); return surface; }
public SurfaceWrapper (Cairo.Context similar, Gdk.Pixbuf source) { Cairo.Surface surface; // There is a bug in Cairo for OSX right now that prevents creating additional accellerated surfaces. if (Platform.IsMac) { surface = new QuartzSurface (Format.ARGB32, source.Width, source.Height); } else if (Platform.IsWindows) { using (var t = similar.GetTarget ()) { surface = t.CreateSimilar (Content.ColorAlpha, source.Width, source.Height); } } else { surface = new ImageSurface (Format.ARGB32, source.Width, source.Height); } using (Context context = new Context (surface)) { Gdk.CairoHelper.SetSourcePixbuf (context, source, 0, 0); context.Paint (); } Surface = surface; Width = source.Width; Height = source.Height; }
public SurfaceWrapper (Cairo.Context similar, int width, int height) { if (Platform.IsMac) { Surface = new QuartzSurface (Cairo.Format.ARGB32, width, height); } else if (Platform.IsWindows) { using (var target = similar.GetTarget ()) { Surface = target.CreateSimilar (Cairo.Content.ColorAlpha, width, height); } } else { Surface = new ImageSurface (Cairo.Format.ARGB32, width, height); } Width = width; Height = height; }
public static void DisposeContext (Cairo.Context cr) { ((IDisposable)cr.GetTarget ()).Dispose (); ((IDisposable)cr).Dispose (); }
private Surface CreateScene(Cairo.Context window_cr, ImageSurface image, int reflect) { var target = window_cr.GetTarget (); Surface surface = target.CreateSimilar (target.Content, image.Width, image.Height + reflect); using (var cr = new Context (surface)) { cr.Save (); cr.SetSource (image); cr.Paint (); cr.Rectangle (0, image.Height, image.Width, reflect); cr.Clip (); Matrix matrix = new Matrix (); matrix.InitScale (1, -1); matrix.Translate (0, -(2 * image.Height) + 1); cr.Transform (matrix); cr.SetSource (image); cr.Paint (); cr.Restore (); Color bg_transparent = BackgroundColor; bg_transparent.A = 0.65; using (var mask = new LinearGradient (0, image.Height, 0, image.Height + reflect)) { mask.AddColorStop (0, bg_transparent); mask.AddColorStop (1, BackgroundColor); cr.Rectangle (0, image.Height, image.Width, reflect); cr.SetSource (mask); cr.Fill (); } } return surface; }
public static Surface CreateSurfaceForPixbuf(Cairo.Context cr, Gdk.Pixbuf pixbuf) { var target = cr.GetTarget (); Surface surface = target.CreateSimilar (target.Content, pixbuf.Width, pixbuf.Height); using (var surface_cr = new Context (surface)) { Gdk.CairoHelper.SetSourcePixbuf (surface_cr, pixbuf, 0.0, 0.0); surface_cr.Paint (); } return surface; }