Beispiel #1
0
        /// <summary>
        /// 截图游戏并保存
        /// </summary>
        public static void ScreenShot()
        {
            if (!Directory.Exists("screenshot"))
            {
                Directory.CreateDirectory("screenshot");
            }

            string path = @"screenshot\" + LogsHelper.GetServerName() + "_" + LogsHelper.GetFilePlayerName() + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff") + "." + DataUtil.Config.sysConfig.capFormat.ToString().ToLower();

            System.Windows.Point p = new System.Windows.Point();
            var screenPoint        = main.WinFormHost.PointToScreen(p);
            int x      = (int)screenPoint.X;
            int y      = (int)screenPoint.Y;
            int width  = Convert.ToInt32(main.WinFormHost.Width);
            int height = Convert.ToInt32(main.WinFormHost.Height);

            var image = ScreenHelper.CaptureScreen(x, y, width, height);

            var format = Path.GetExtension(path) == ".jpg"
                ? ImageFormat.Jpeg
                : ImageFormat.Png;

            image.Save(path, format);
            AddLog("截圖已經保存到文件" + path);
        }
Beispiel #2
0
        /// <summary>
        /// 截图游戏并保存
        /// </summary>
        public static void ScreenShot()
        {
            if (!Directory.Exists("screenshot"))
            {
                Directory.CreateDirectory("screenshot");
            }
            string path = @"screenshot\" + LogsHelper.GetServerName() + "_" + LogsHelper.GetFilePlayerName() + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff") + "." + DataUtil.Config.sysConfig.capFormat.ToString().ToLower();

            var document = main.mainWeb.Document as HTMLDocument;

            if (document == null)
            {
                return;
            }

            if (document.url.Contains(".swf?"))
            {
                var viewObject = document.getElementsByTagName("embed").item(0, 0) as IViewObject;
                if (viewObject == null)
                {
                    return;
                }

                var width  = ((HTMLEmbed)viewObject).clientWidth;
                var height = ((HTMLEmbed)viewObject).clientHeight;
                TakeScreenshot(width, height, viewObject, path);
            }
            else
            {
                if (DataUtil.Game.gameServer == (int)GameInfo.ServersList.American || DataUtil.Game.gameServer == (int)GameInfo.ServersList.AmericanR18)
                {
                    var gameFrame = document.getElementById("externalContainer").document as HTMLDocument;
                    if (gameFrame == null)
                    {
                        return;
                    }

                    IViewObject viewObject = null;
                    int         width = 0, height = 0;
                    var         swf = gameFrame.getElementById("externalswf");
                    if (swf == null)
                    {
                        return;
                    }
                    Func <dynamic, bool> function = target =>
                    {
                        if (target == null)
                        {
                            return(false);
                        }
                        viewObject = target as IViewObject;
                        if (viewObject == null)
                        {
                            return(false);
                        }
                        width  = int.Parse(target.width);
                        height = int.Parse(target.height);
                        return(true);
                    };
                    if (!function(swf as HTMLEmbed) && !function(swf as HTMLObjectElement))
                    {
                        return;
                    }

                    TakeScreenshot(width, height, viewObject, path);
                }
                else
                {
                    var gameFrame = document.getElementById("game_frame").document as HTMLDocument;
                    if (gameFrame == null)
                    {
                        return;
                    }

                    var frames = document.frames;
                    for (var i = 0; i < frames.length; i++)
                    {
                        var item     = frames.item(i);
                        var provider = item as IServiceProvider;
                        if (provider == null)
                        {
                            continue;
                        }

                        object ppvObject;
                        provider.QueryService(typeof(IWebBrowserApp).GUID, typeof(IWebBrowser2).GUID, out ppvObject);
                        var webBrowser = ppvObject as IWebBrowser2;

                        var iframeDocument = webBrowser?.Document as HTMLDocument;
                        if (iframeDocument == null)
                        {
                            continue;
                        }

                        IViewObject viewObject = null;
                        int         width = 0, height = 0;
                        var         swf = iframeDocument.getElementById("externalswf");
                        if (swf == null)
                        {
                            continue;
                        }
                        Func <dynamic, bool> function = target =>
                        {
                            if (target == null)
                            {
                                return(false);
                            }
                            viewObject = target as IViewObject;
                            if (viewObject == null)
                            {
                                return(false);
                            }
                            width  = int.Parse(target.width);
                            height = int.Parse(target.height);
                            return(true);
                        };
                        if (!function(swf as HTMLEmbed) && !function(swf as HTMLObjectElement))
                        {
                            continue;
                        }

                        TakeScreenshot(width, height, viewObject, path);

                        break;
                    }
                }
            }
        }