示例#1
0
        public static string ResizeConstabLogo(string filepath)
        {
            //need to convert image to png
            try
            {
                using (MagickImage image = new MagickImage(filepath))
                {
                    image.Write(Constants.TempLogoFile);
                }

                using (MagickImage image = new MagickImage(Constants.TempLogoFile))
                {
                    MagickGeometry size = new MagickGeometry(196, 196);
                    size.IgnoreAspectRatio = false;
                    image.Resize(size);
                    image.Write(Constants.TempImgFile);
                }
                string base64;
                using (Image img = new Bitmap(Constants.TempImgFile))
                {
                    base64 = img.ToBase64Encoded();
                }
                ImageDiskCache.RemoveItemsInCache();
                return(base64);
            }
            catch
            {
                throw new Exception("Unable to save icon");
            }
        }
        /// <summary>
        /// Adds the specified image to the temporary disk cache
        /// </summary>
        /// <param name="screenshot">The Image to save to the cache</param>
        /// <returns>True if save did not throw an exception (it was successful), false otherwise.</returns>
        /// <remarks>This image will get removed from the cache once utilised.</remarks>
        public static bool SaveScreenshotToCache(Image screenshot)
        {
            bool saved = false;

            ImageDiskCache cache = new ImageDiskCache();
            cache.AddImage("temp", screenshot);
       
            return saved;
        }
示例#3
0
        /// <summary>
        /// Adds the specified image to the temporary disk cache
        /// </summary>
        /// <param name="screenshot">The Image to save to the cache</param>
        /// <returns>True if save did not throw an exception (it was successful), false otherwise.</returns>
        /// <remarks>This image will get removed from the cache once utilised.</remarks>
        public static bool SaveScreenshotToCache(Image screenshot)
        {
            bool saved = false;

            ImageDiskCache cache = new ImageDiskCache();

            cache.AddImage("temp", screenshot);

            return(saved);
        }
示例#4
0
        private async void FullpageScreenshotByScrolling()
        {
            int scrollHeight =  GetDocHeight();
            if (scrollHeight == 0)
            {
                FireScreenshotCompleteEvent(false);
                return;
            }

            Enabled = false;
            int viewportHeight = ClientRectangle.Size.Height;
            int viewportWidth = ClientRectangle.Size.Width;
            await GetBrowser().MainFrame.EvaluateScriptAsync("(function() { document.documentElement.style.overflow = 'hidden'; })();");
            int count = 0;
            int pageLeft = scrollHeight;
            bool atBottom = false;
            Debug.WriteLine($"OUTSIDE --- PAGE LEFT: {pageLeft}. VIEWPORT HEIGHT: {viewportHeight}");
            ImageDiskCache cache = new ImageDiskCache();

            while (!atBottom)
            {
                if (pageLeft > viewportHeight)
                {
                    //if we can scroll using the viewport, let's do that
                    await GetBrowser().MainFrame.EvaluateScriptAsync("(function() { window.scroll(0," + (count * viewportHeight) + "); })();");
                    count++;
                    await PutTaskDelay();  //we do need these delays. Some pages, like facebook, may need to load viewport content.
                    using (Bitmap image = GetCurrentViewScreenshot())
                    {
                        cache.AddImage(count, image);
                    }
                    await GetBrowser().MainFrame.EvaluateScriptAsync("(function() { var elements = document.querySelectorAll('*'); for (var i = 0; i < elements.length; i++) { var position = window.getComputedStyle(elements[i]).position; if (position === 'fixed') { elements[i].style.visibility = 'hidden'; } } })(); ");
                }
                else 
                {
                    //find out what's left of the page to scroll, then take screenshot
                    //if it's the last image, we're going to need to crop what we need, as it'll take
                    //a capture of the entire viewport.

                    await GetBrowser().MainFrame.EvaluateScriptAsync("(function() { window.scrollBy(0," + pageLeft + "); })();");
                    atBottom = true;
                    count++;

                    await PutTaskDelay();
                    Rectangle cropRect = new Rectangle(new Point(0, viewportHeight - pageLeft), new Size(viewportWidth, pageLeft));

                    using (Bitmap src = GetCurrentViewScreenshot())
                    using (Bitmap target = new Bitmap(cropRect.Width, cropRect.Height))
                    using (Graphics g = Graphics.FromImage(target))
                    {
                        g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), cropRect, GraphicsUnit.Pixel);
                        cache.AddImage(count, target);
                    }
                  
                }

                pageLeft = pageLeft - viewportHeight;
                Debug.WriteLine($"IN WHILE --- PAGE LEFT: {pageLeft}. VIEWPORT HEIGHT: {viewportHeight}");
            }//end while
            await GetBrowser().MainFrame.EvaluateScriptAsync("(function() { document.documentElement.style.overflow = 'auto'; })();");
            await GetBrowser().MainFrame.EvaluateScriptAsync("javascript:var s = function() { document.body.scrollTop = document.documentElement.scrollTop = 0;}; s();");
            await GetBrowser().MainFrame.EvaluateScriptAsync("(function() { var elements = document.querySelectorAll('*'); for (var i = 0; i < elements.length; i++) { var position = window.getComputedStyle(elements[i]).position; if (position === 'fixed') { elements[i].style.visibility = 'visible'; } } })(); ");
            Enabled = true;
            WaitWindow.Show(GetScreenshot, Resources.strings.CombineScreenshots);
            FireScreenshotCompleteEvent(true);
        }