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

FlattenImage() public method

public FlattenImage ( ) : void
return void
        public void FlattenImage()
        {
            if (UserLayers.Count < 2)
                throw new InvalidOperationException ("Cannot flatten image because there is only one layer.");

            // Find the "bottom" layer
            var bottom_layer = UserLayers[0];
            var old_surf = bottom_layer.Surface;

            // Replace the bottom surface with the flattened image,
            // and dispose the old surface
            bottom_layer.Surface = GetFlattenedImage ();
            (old_surf as IDisposable).Dispose ();

            // Reset our layer pointer to the only remaining layer
            current_layer = 0;

            // Delete all other layers
            while (UserLayers.Count > 1)
                UserLayers.RemoveAt (1);

            PintaCore.Layers.OnLayerRemoved ();
            Workspace.Invalidate ();
        }

Usage Example

Example #1
0
		private void HandlePintaCoreActionsImageFlattenActivated (object sender, EventArgs e)
		{
			Document doc = PintaCore.Workspace.ActiveDocument;

			PintaCore.Tools.Commit ();

			var oldBottomSurface = doc.UserLayers[0].Surface.Clone ();

			CompoundHistoryItem hist = new CompoundHistoryItem ("Menu.Image.Flatten.png", Catalog.GetString ("Flatten"));

			for (int i = doc.UserLayers.Count - 1; i >= 1; i--)
				hist.Push (new DeleteLayerHistoryItem (string.Empty, string.Empty, doc.UserLayers[i], i));

			doc.FlattenImage ();

			hist.Push (new SimpleHistoryItem (string.Empty, string.Empty, oldBottomSurface, 0));
			doc.History.PushNewItem (hist);
		}