Exemple #1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <IGH_Goo> goos = new List <IGH_Goo>();

            if (!DA.GetDataList(0, goos))
            {
                return;
            }

            Ml.Composition composition = new Ml.Composition();

            foreach (IGH_Goo goo in goos)
            {
                Ml.Layer layer = new Ml.Layer();
                if (goo.CastTo <Ml.Layer>(out layer))
                {
                    composition.Layers.Add(new Ml.Layer(layer));
                }
            }

            Bitmap bitmap = composition.GetBitmap();

            DA.SetData(0, new Image(bitmap));
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo = null;
            Bitmap  top = new Bitmap(100, 100);

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetBitmap(ref top))
            {
                return;
            }

            Mp.Layer topLayer = new Mp.Layer(top);

            IGH_Goo gooT   = null;
            Bitmap  bottom = new Bitmap(100, 100);

            if (!DA.GetData(1, ref gooT))
            {
                return;
            }
            if (!gooT.TryGetBitmap(ref bottom))
            {
                return;
            }

            Mp.Layer bottomLayer = new Mp.Layer(bottom);

            IGH_Goo gooM    = null;
            Image   img     = new Image();
            bool    hasMask = false;
            Bitmap  mask    = new Bitmap(100, 100);

            if (DA.GetData(2, ref gooM))
            {
                if (gooM.TryGetImage(ref img))
                {
                    hasMask = true;
                    img.SwapChannel(Image.Channels.Luminance, Image.Channels.Alpha);
                    mask = img.Bitmap;
                }
            }

            int blendMode = 0;

            DA.GetData(3, ref blendMode);

            double opacity = 1.0;

            DA.GetData(4, ref opacity);

            topLayer.BlendMode = (Mp.Layer.BlendModes)blendMode;
            topLayer.Opacity   = 100 * opacity;
            if (hasMask)
            {
                topLayer.Mask = mask;
            }

            Mp.Composition composition = new Mp.Composition();
            composition.Layers.Add(bottomLayer);
            composition.Layers.Add(topLayer);

            DA.SetData(0, new Image(composition.GetBitmap()));
        }