Exemplo n.º 1
0
        private void btnShot_Click(object sender, RoutedEventArgs e)
        {
            int                  areaHeight = 0, areaWidth = 0;
            Position             areaPos = null;
            Position             dialogPos;
            JavaScriptSerializer json = new JavaScriptSerializer();
            Invoice              inv  = listView.SelectedItem as Invoice;

            string cmd          = string.Format("JSON.stringify($(\"#dialog-body\").offset())");
            string dialogOffset = (string)browser.GetBrowser().MainFrame.EvaluateScriptAsync(cmd).Result.Result;

            if (dialogOffset == null)
            {
                return;
            }
            dialogPos = json.Deserialize <Position>(dialogOffset);

            browser.GetBrowser().GetFrameIdentifiers().ForEach(t =>
            {
                CefSharp.IFrame frame = browser.GetBrowser().GetFrame(t);
                if (frame.IsMain)
                {
                    return;
                }
                else
                {
                    cmd = string.Format("JSON.stringify($(\"#print_area\").offset())");
                    string areaOffset = (string)frame.EvaluateScriptAsync(cmd).Result.Result;
                    areaPos           = json.Deserialize <Position>(areaOffset);
                    cmd        = string.Format("$(\"#print_area\").outerHeight()");
                    areaHeight = (int)frame.EvaluateScriptAsync(cmd).Result.Result;
                    cmd        = string.Format("$(\"#print_area\").outerWidth()");
                    areaWidth  = (int)frame.EvaluateScriptAsync(cmd).Result.Result;
                }
            });
            if (areaPos != null)
            {
                areaPos += dialogPos;
                Int32Rect rect = new Int32Rect((int)areaPos.Left, (int)areaPos.Top, areaWidth, areaHeight);
                System.Windows.Controls.Image contentImage = browser.Content as System.Windows.Controls.Image;
                BitmapSource  bs  = contentImage.Source.Clone() as BitmapSource;
                CroppedBitmap img = new CroppedBitmap(bs, rect);
                inv.Result = img;
            }
        }
Exemplo n.º 2
0
        public static cefS.JavascriptResponse uJsExec(uChrome agrBrowser, string argJs)
        {
            List <long> frameIdList = agrBrowser.uBrowser.GetBrowser().GetFrameIdentifiers();

            cefS.IFrame frame = agrBrowser.uBrowser.GetBrowser().GetFrame(frameIdList.First());
            var         t     = frame.EvaluateScriptAsync(argJs);

            t.Wait();
            return(t.Result);
        }