Exemple #1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Hp.Drawing drawing = new Hp.Drawing();
            if (!DA.GetData <Hp.Drawing>(0, ref drawing))
            {
                return;
            }
            Sm.DrawingVisual dwg = drawing.ToGeometryVisual();

            double width  = drawing.Width;
            double height = drawing.Height;

            if (width < 100)
            {
                width = 100;
            }
            if (height < 100)
            {
                height = 100;
            }

            img     = dwg.ToBitmap(width, height);
            message = drawing.ToString();
            UpdateMessage();
        }
Exemple #2
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)
        {
            Hp.Drawing drawing = new Hp.Drawing();
            if (!DA.GetData <Hp.Drawing>(0, ref drawing))
            {
                return;
            }

            int    dpi       = 96;
            string path      = "C:\\Users\\Public\\Documents\\";
            string name      = DateTime.UtcNow.ToString("yyyy-dd-M_HH-mm-ss");;
            int    extension = 0;
            string format    = ".png";
            bool   save      = false;

            if (!DA.GetData(1, ref dpi))
            {
                return;
            }
            bool hasPath = DA.GetData(2, ref path);
            bool hasName = DA.GetData(3, ref name);

            if (!DA.GetData(4, ref extension))
            {
                return;
            }
            if (!DA.GetData(5, ref save))
            {
                return;
            }

            Si.BitmapEncoder encoding = new Si.PngBitmapEncoder();
            switch (extension)
            {
            case 1:
                encoding = new Si.JpegBitmapEncoder();
                format   = ".jpeg";
                break;

            case 2:
                encoding = new Si.BmpBitmapEncoder();
                format   = ".bmp";
                break;

            case 3:
                encoding = new Si.TiffBitmapEncoder();
                format   = ".tiff";
                break;

            case 4:
                encoding = new Si.GifBitmapEncoder();
                format   = ".gif";
                break;
            }

            if (!hasPath)
            {
                if (this.OnPingDocument().FilePath != null)
                {
                    path = Path.GetDirectoryName(this.OnPingDocument().FilePath) + "\\";
                }
            }
            else
            {
                path += "//";
            }

            string filepath = path + name + format;

            Sm.DrawingVisual dwg    = drawing.ToGeometryVisual();
            Bitmap           bitmap = dwg.ToBitmap(drawing.Width, drawing.Height, dpi, encoding);

            if (save)
            {
                bitmap.Save(filepath);
                bitmap.Dispose();
            }

            DA.SetData(0, filepath);
        }