LitDev.LDTextWindow.Capture C# (CSharp) Method

Capture() public static method

Save the TextWindow as an image file (png, jpg, bmp, gif, tiff or ico). The window must be visible and a short delay may be required after updating the window before calling.
public static Capture ( Primitive fileName, Primitive border ) : Primitive
fileName Primitive /// The file to save the image to (*.png, *.jpg, *.bmp, *.gif, *.tiff or *.ico). /// If this is set to "", then the image is created internally as an ImageList. ///
border Primitive /// Include the window border ("True" or "False"). ///
return Primitive
        public static Primitive Capture(Primitive fileName, Primitive border)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Type ShapesType = typeof(Shapes);
            Type ImageListType = typeof(Microsoft.SmallBasic.Library.ImageList);
            Dictionary<string, BitmapSource> _savedImages;
            TextWindow.Show();
            Utilities.bTextWindow = true;
            Utilities.bBorder = border;
            try
            {
                IntPtr _hWnd = User32.FindWindow(null, TextWindow.Title);
                Image img = Utilities.captureWindow(_hWnd);
                if (fileName == "")
                {
                    InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                    {
                        try
                        {
                            _savedImages = (Dictionary<string, BitmapSource>)ImageListType.GetField("_savedImages", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                            string shapeName = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).Invoke(null, new object[] { "ImageList" }).ToString();
                            _savedImages[shapeName] = FastPixel.GetBitmapImage((Bitmap)img);
                            return shapeName;
                        }
                        catch (Exception ex)
                        {
                            Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        }
                        return "";
                    });
                    return FastThread.InvokeWithReturn(ret).ToString();
                }
                else
                {
                    Utilities.saveImage(img, fileName);
                }
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return "";
        }