Pinta.Core.Document.GetClippedLayer C# (CSharp) Method

GetClippedLayer() public method

public GetClippedLayer ( int index ) : ImageSurface
index int
return Cairo.ImageSurface
        public ImageSurface GetClippedLayer(int index)
        {
            Cairo.ImageSurface surf = new Cairo.ImageSurface (Cairo.Format.Argb32, ImageSize.Width, ImageSize.Height);

            using (Cairo.Context g = new Cairo.Context (surf)) {
                g.AppendPath(Selection.SelectionPath);
                g.Clip ();

                g.SetSource (UserLayers[index].Surface);
                g.Paint ();
            }

            return surf;
        }

Usage Example

Example #1
0
        private void HandlerPintaCoreActionsEditCopyActivated(object sender, EventArgs e)
        {
            Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
            if (PintaCore.Tools.CurrentTool.TryHandleCopy(cb))
            {
                return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit();

            using (ImageSurface src = doc.GetClippedLayer(doc.CurrentUserLayerIndex)) {
                Gdk.Rectangle rect = doc.GetSelectedBounds(true);
                if (rect.Width == 0 || rect.Height == 0)
                {
                    return;
                }

                ImageSurface dest = new ImageSurface(Format.Argb32, rect.Width, rect.Height);

                using (Context g = new Context(dest)) {
                    g.SetSourceSurface(src, -rect.X, -rect.Y);
                    g.Paint();
                }

                cb.Image = dest.ToPixbuf();

                (dest as IDisposable).Dispose();
            }
        }