public void It_should_render_rounded_panels()
        {
            var renderer = new BitmapRenderer();

            var vbox = new HBox();

            var borders = new[]
            {
                new [] { "10 0 0 0", "0 10 0 0", "0 0 10 0", "0 0 0 10" },
                new [] { "10 10 0 0", "10 0 10 0", "10 0 0 10", "0 0 10 10" },
                new [] { "10 10 10 0", "10 0 10 10", "10 10 0 10", "10 10 10 10" }
            };

            foreach (var boxLine in borders)
            {
                var hbox = new HBox();
                foreach (var border in boxLine)
                {
                    hbox.AddComponent(new Panel
                    {
                        Margin          = new Spacer(1),
                        BackgroundColor = Color.Blue,
                        Width           = 22,
                        Height          = 22,
                        BorderRadius    = BorderRadius.Parse(border)
                    });
                }
                vbox.AddComponent(hbox);
            }

            var bmp = new Bitmap(300, 40);

            renderer.Render(new Form(vbox), bmp);
            BitmapComparer.CompareBitmaps("panels_rounded", bmp);
        }
Example #2
0
        private bool DragAreaWithVerticalCheck(Point start, Point end)
        {
            using (var capture1 = new ScreenCapture(VerticalCheckRect.Value))
            {
                MouseUtils.RightDrag(start, end, ScrollDelay);
                using (var capture2 = new ScreenCapture(VerticalCheckRect.Value))
                {
                    if (!BitmapComparer.AreBitmapsIdentical(capture1.Bitmap, capture2.Bitmap))
                    {
                        sm_log.Info("Drag successful");
                        return(true);
                    }

                    sm_log.Warn(Invariant($"Attempted to drag from {start} to {end} but detected no vertical movement. Waiting a little while before checking again..."));
                    ThreadUtils.SleepOrAbort(100 + ScrollDelay);

                    using (var capture3 = new ScreenCapture(VerticalCheckRect.Value))
                    {
                        if (!BitmapComparer.AreBitmapsIdentical(capture1.Bitmap, capture3.Bitmap))
                        {
                            sm_log.Info("Drag successful");
                            return(true);
                        }

                        sm_log.Warn("Still no vertical movement detected");
                        return(false);
                    }
                }
            }
        }
Example #3
0
        private static void ScrollToTop()
        {
            sm_log.Info("Scrolling sidebar to top");

            var       sidebarRect   = new Rectangle(ScreenCapture.ScreenBounds.Location, new Size(ScreenLayout.SidebarWidth, SidebarUtil.MaxHeight));
            const int maxIterations = 100;

            for (int i = 0; i < maxIterations; i++)
            {
                // Drag upwards as much as we can
                MouseUtils.RightDrag(sidebarRect.Location, new Point(sidebarRect.Left, ScreenCapture.ScreenBounds.Height - 1));

                // To check if we've reached the top, try to drag upwards one more pixel. If nothing changes,
                // we're almost definitely at the top!
                using (var capture1 = new ScreenCapture(sidebarRect))
                {
                    MouseUtils.RightDrag(sidebarRect.Location, sidebarRect.Location.Add(new Point(0, 1)));
                    using (var capture2 = new ScreenCapture(sidebarRect))
                    {
                        if (BitmapComparer.AreBitmapsIdentical(capture1.Bitmap, capture2.Bitmap))
                        {
                            return;
                        }
                    }
                }
            }

            throw new AnalysisException(Invariant($"Failed to scroll to the top of the sidebar after {maxIterations} attempts."));
        }
Example #4
0
        public void CompareWorksWithNoOptions()
        {
            var target = new BitmapComparer();
            var result = target.Compare(FirstImage, SecondImage);

            result.Save(string.Format(OutputFormat, "CompareWorksWithNullOptions"), SecondImage.RawFormat);
        }
Example #5
0
        public void Test1()
        {
            IBitmapComparer bitmapComparer = new BitmapComparer();

            var driver = new ChromeDriver(@"Drivers/");

            //var driver = new InternetExplorerDriver(@"Drivers/");

            driver.Navigate().GoToUrl("http://www.thelondonclinic.co.uk");

            WaitForElementToAppear(driver, 2000, By.Id("patient"));

            driver.FindElement(By.Id("patient")).Click();

            WaitForElementToAppear(driver, 2000, By.LinkText("Why choose The London Clinic?"));

            driver.FindElementByLinkText("Why choose The London Clinic?").Click();

            var s = driver.GetScreenshot();

            s.SaveAsFile(@"pic.png", ImageFormat.Png);
            s.SaveAsFile(@"pic2.png", ImageFormat.Png);

            var result = bitmapComparer.AreSame(@"pic.png", @"pic2.png");

            Assert.IsTrue(result);
        }
Example #6
0
        public async Task It_should_allow_concurrent_processing()
        {
            var bmps = await Task.WhenAll(Enumerable.Range(0, 100).Select(_ => Task.Run(Generate)));

            BitmapComparer.CompareBitmaps("form", bmps.First());
            BitmapComparer.CompareBitmaps("form", bmps.Last());
        }
Example #7
0
        public void It_should_render_text_with_different_line_heights()
        {
            var renderer = new BitmapRenderer();
            var content  = new HBox {
                Width = SizeUnit.Unlimited
            };

            content.AddComponent(new Panel
            {
                Width           = 100,
                Height          = SizeUnit.Unlimited,
                BackgroundColor = Color.Yellow,
                Margin          = new Spacer(1),
                Inner           = new Label
                {
                    TextColor  = Color.Red,
                    Font       = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic),
                    Text       = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?",
                    LineHeight = 1.2f
                }
            });

            content.AddComponent(new Panel
            {
                Width           = 100,
                Height          = SizeUnit.Unlimited,
                BackgroundColor = Color.Yellow,
                Margin          = new Spacer(1),
                Inner           = new Label
                {
                    TextColor  = Color.Red,
                    Font       = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic),
                    Text       = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?",
                    LineHeight = 2f
                }
            });

            content.AddComponent(new Panel
            {
                Width           = 100,
                Height          = SizeUnit.Unlimited,
                BackgroundColor = Color.Yellow,
                Margin          = new Spacer(1),
                Inner           = new Label
                {
                    TextColor  = Color.Red,
                    Font       = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic),
                    Text       = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?",
                    LineHeight = 0.8f
                }
            });

            var form = new Form(content);

            var bmp = new Bitmap(300, 400);

            renderer.Render(form, bmp);
            BitmapComparer.CompareBitmaps("text_box_line_height", bmp);
        }
        public void CompareThrowsWhenImagesAreNotSameHeight()
        {
            var firstBitmap  = new Bitmap(10, 10);
            var secondBitmap = new Bitmap(10, 20);

            var target = new BitmapComparer(null);

            Should.Throw <ArgumentException>(() => target.Compare(firstBitmap, secondBitmap));
        }
Example #9
0
        public void CompareThrowsWhenImagesAreNotSameHeight()
        {
            var firstBitmap  = new Bitmap(10, 10);
            var secondBitmap = new Bitmap(10, 20);

            var target = new BitmapComparer(null);

            target.Compare(firstBitmap, secondBitmap);
        }
Example #10
0
        private void button_Compare_Click(object sender, RoutedEventArgs e)
        {
            var shownComparisons = new HashSet <Tuple <string, string> >(new ReverseTupleComparer());

            long      total     = BitmapComparer.GetPermutationCount();
            const int MAX_COUNT = 5000000;
            IDictionary <Tuple <string, string>, float> diffMap = null;
            int startIdx = 0;

restart:
            GC.Collect();
            Action task = new Action(() =>
            {
                diffMap = BitmapComparer.CreateDiffMapFromDCTCache(MAX_COUNT, startIdx);
            });

            WorkWindow wwin = new WorkWindow($"Generating diff map...\n\n[{startIdx}] out of [{total}]", task);

            wwin.Owner = this;
            wwin.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            wwin.SetPBarScore(startIdx, total);
            wwin.ShowDialog();

            float threshold = float.Parse(txt_Threshold.Text, CultureInfo.InvariantCulture);

            var filteredDiffMap = diffMap.Where((kvp) => kvp.Value >= threshold);

            long idx = 0;

            foreach (var kvp in filteredDiffMap.Distinct())
            {
                string file1 = kvp.Key.Item1;
                string file2 = kvp.Key.Item2;

                var tuple = new Tuple <string, string>(file1, file2);

                if (shownComparisons.Contains(tuple))
                {
                    continue;
                }

                float diff = kvp.Value;

                CompWindow cwin = new CompWindow(file1, file2, diff);
                cwin.Owner = this;
                cwin.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                cwin.ShowDialog();

                shownComparisons.Add(tuple);
                idx++;
            }
            if (diffMap.Count != 0)
            {
                startIdx += diffMap.Count;
                goto restart;
            }
        }
Example #11
0
        public void It_should_render_images()
        {
            var redBlue    = CreateBitmap(Brushes.Red, Brushes.Blue, 400, 400);
            var blueYellow = CreateBitmap(Brushes.Blue, Brushes.Yellow, 30, 30);

            var renderer = new BitmapRenderer();
            var vBox     = new VBox();
            var hBox     = new HBox();

            AddComponent(hBox, new Image {
                Src = redBlue, Width = 40, Height = 40, Scaling = ImageScaling.Uniform
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 40, Height = 30, Scaling = ImageScaling.Uniform, Alignment = Alignment.Center
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 40, Height = 30, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("center left")
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 40, Height = 30, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("center right")
            });
            vBox.AddComponent(hBox);
            hBox = new HBox();
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 30, Height = 40, Scaling = ImageScaling.Uniform, Alignment = Alignment.Center
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 30, Height = 40, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("top center")
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 30, Height = 40, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("bottom center")
            });
            vBox.AddComponent(hBox);
            hBox = new HBox();
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 10, Height = 20, Scaling = ImageScaling.Fill
            });
            AddComponent(hBox, new Image {
                Src = blueYellow, Scaling = ImageScaling.None
            });
            AddComponent(hBox, new Image {
                Src = blueYellow, Width = 20, Height = 20, Alignment = Alignment.Center, Scaling = ImageScaling.None
            });
            AddComponent(hBox, new Image {
                Src = blueYellow, Width = 20, Height = 20, Alignment = Alignment.Parse("top left"), Scaling = ImageScaling.None
            });
            AddComponent(hBox, new Image {
                Src = blueYellow, Width = 20, Height = 20, Alignment = Alignment.Parse("bottom right"), Scaling = ImageScaling.None
            });
            vBox.AddComponent(hBox);
            var form = new Form(vBox);

            var bmp = renderer.Render(form);

            BitmapComparer.CompareBitmaps("bitmaps", bmp);
        }
Example #12
0
        private void button_RestoreCache(object sender, RoutedEventArgs e)
        {
            OpenFileDialog diag = new OpenFileDialog();

            if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string path = diag.FileName;
                BitmapComparer.RestoreDiffCacheFromDisk(path);
                System.Windows.MessageBox.Show("DONE!");
            }
        }
        public void CompareWorksWithIdenticalImages(AnalyzerTypes aType, BoundingBoxModes bMode, LabelerTypes lType)
        {
            var target = new BitmapComparer(new CompareOptions
            {
                AnalyzerType    = aType,
                BoundingBoxMode = bMode,
                Labeler         = lType
            });
            var result = target.Compare(FirstImage, FirstImage);

            result.Save(string.Format(OutputFormat, $"CompareWorksWithIdenticalImages_{aType}_{bMode}_{lType}"), SecondImage.RawFormat);
        }
Example #14
0
 public void ImageDiffThrowsWhenDetectionPaddingIsLessThanZero()
 {
     var target = new BitmapComparer(new CompareOptions
     {
         BoundingBoxColor   = Color.Red,
         BoundingBoxMode    = BoundingBoxModes.Single,
         AnalyzerType       = AnalyzerTypes.ExactMatch,
         DetectionPadding   = -2,
         BoundingBoxPadding = 2,
         Labeler            = LabelerTypes.Basic
     });
 }
Example #15
0
 public bool Equals(SteamAppTemplate other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(AppId == other.AppId && Name == other.Name &&
            BitmapComparer.Compare((Bitmap)Icon, (Bitmap)other.Icon));
 }
        private DisposableList <ScreenCapture> GetSidebarCaptures()
        {
            // Chop a bit off the bottom of the image because it starts to fade out there, making it more difficult to compare
            var captureRect = new Rectangle(SidebarRect.Left, SidebarRect.Top, SidebarRect.Width, SidebarRect.Height - 70);

            sm_log.Info("Capturing section 0 of the sidebar");
            var prevCapture = new ScreenCapture(captureRect);

            var captures = new DisposableList <ScreenCapture> {
                prevCapture.Clone()
            };

            int scrollDistance = CalculateScrollDistance();

            const int maxIterations = 100;
            int       i             = 0;

            for (; i < maxIterations; i++)
            {
                MouseUtils.RightDrag(SidebarRect.Location.Add(new Point(0, scrollDistance)), SidebarRect.Location);

                // Check if we've reached the bottom
                if (SidebarUtil.FindVisibleSidebarHeight() <= SidebarUtil.MaxHeight)
                {
                    break;
                }

                // Capture the next bit of the sidebar
                prevCapture.Dispose();
                prevCapture = new ScreenCapture(captureRect);
                sm_log.Info(Invariant($"Capturing section {i + 1} of the sidebar"));
                captures.Add(prevCapture.Clone(new Rectangle(0, prevCapture.Rect.Height - scrollDistance, prevCapture.Rect.Width, scrollDistance)));
            }

            if (i >= maxIterations)
            {
                throw new AnalysisException(Invariant($"Couldn't find the bottom of the sidebar after {i} attempts."));
            }

            // Capture the final bit of the sidebar
            var finalCapture = new ScreenCapture(SidebarRect);

            // Work out where it overlaps the previous part, and capture the overlap
            int overlap = BitmapComparer.CalculateVerticalOverlap(prevCapture.Bitmap, finalCapture.Bitmap, m_overlapComparer, 0);

            sm_log.Info("Capturing final section of the sidebar");
            captures.Add(finalCapture.Clone(new Rectangle(0, overlap, finalCapture.Rect.Width, finalCapture.Rect.Height - overlap)));

            prevCapture.Dispose();
            return(captures);
        }
Example #17
0
        public void CompareWorksWithDifferentImages(AnalyzerTypes aType, BoundingBoxModes bMode, LabelerTypes lType)
        {
            var target = new BitmapComparer(new CompareOptions
            {
                BoundingBoxColor   = Color.Red,
                BoundingBoxMode    = bMode,
                AnalyzerType       = aType,
                DetectionPadding   = 2,
                BoundingBoxPadding = 2,
                Labeler            = lType
            });
            var result = target.Compare(FirstImage, SecondImage);

            result.Save(string.Format(OutputFormat, string.Format("CompareWorksWithDifferentImages_{0}_{1}_{2}", aType, bMode, lType)), SecondImage.RawFormat);
        }
        public void EqualsReturnsTrueWithNullImages(AnalyzerTypes aType, BoundingBoxModes bMode, LabelerTypes lType)
        {
            var target = new BitmapComparer(new CompareOptions
            {
                BoundingBoxColor   = Color.Red,
                BoundingBoxMode    = bMode,
                AnalyzerType       = aType,
                DetectionPadding   = 2,
                BoundingBoxPadding = 2,
                Labeler            = lType
            });
            var result = target.Equals(null, null);

            result.ShouldBeTrue();
        }
Example #19
0
        public Comparer()
        {
            var options = new CompareOptions
            {
                AnalyzerType             = AnalyzerTypes.CIE76,
                JustNoticeableDifference = 3,
                DetectionPadding         = 2,
                Labeler            = LabelerTypes.ConnectedComponentLabeling,
                BoundingBoxColor   = Color.Red,
                BoundingBoxPadding = 2,
                BoundingBoxMode    = BoundingBoxModes.Multiple
            };

            innerComparer = new BitmapComparer(options);
        }
Example #20
0
        public void EqualsReturnsFalseWithNullSecondImage(AnalyzerTypes aType, BoundingBoxModes bMode, LabelerTypes lType)
        {
            var target = new BitmapComparer(new CompareOptions
            {
                BoundingBoxColor   = Color.Red,
                BoundingBoxMode    = bMode,
                AnalyzerType       = aType,
                DetectionPadding   = 2,
                BoundingBoxPadding = 2,
                Labeler            = lType
            });
            var result = target.Equals(FirstImage, null);

            Assert.IsFalse(result);
        }
        public void EqualsReturnsFalseWithDifferentImage(AnalyzerTypes aType, BoundingBoxModes bMode, LabelerTypes lType)
        {
            var target = new BitmapComparer(new CompareOptions
            {
                BoundingBoxColor   = Color.Red,
                BoundingBoxMode    = bMode,
                AnalyzerType       = aType,
                DetectionPadding   = 2,
                BoundingBoxPadding = 2,
                Labeler            = lType
            });
            var result = target.Equals(FirstImage, SecondImage);

            result.ShouldBeFalse();
        }
Example #22
0
        public void EqualsReturnsTrueWithSameImage(AnalyzerTypes aType, BoundingBoxModes bMode, LabelerTypes lType)
        {
            var target = new BitmapComparer(new CompareOptions
            {
                BoundingBoxColor   = Color.Red,
                BoundingBoxMode    = bMode,
                AnalyzerType       = aType,
                DetectionPadding   = 2,
                BoundingBoxPadding = 2,
                Labeler            = lType
            });
            var newInstanceOfFirstImage = new Bitmap(TestImage1);
            var result = target.Equals(FirstImage, newInstanceOfFirstImage);

            Assert.IsTrue(result);
        }
Example #23
0
        public void It_should_render_panels_and_hboxes()
        {
            var renderer = new BitmapRenderer();

            var hbox = new HBox {
                Alignment = Alignment.Center
            };

            hbox.AddComponent(new Panel
            {
                BackgroundColor = Color.Yellow,
                Padding         = new Spacer(5),
                Border          = new Border(3, Color.Red),
                Alignment       = new Alignment(VerticalAlignment.Bottom)
            });
            hbox.AddComponent(new Panel
            {
                BackgroundColor = Color.Green,
                Padding         = new Spacer(10, 5),
                Border          = new Border(2, Color.Red),
                Alignment       = new Alignment(VerticalAlignment.Center)
            });
            hbox.AddComponent(new Panel
            {
                BackgroundColor = Color.Blue,
                Padding         = new Spacer(15, 5),
                Border          = new Border(1, Color.Red)
            });
            var panel = new Panel
            {
                Width           = SizeUnit.Unlimited,
                Height          = SizeUnit.Unlimited,
                BackgroundColor = Color.LightSteelBlue,
                Padding         = new Spacer(2),
                Inner           = hbox,
            };
            var form = new Form(panel);

            var bmp = new Bitmap(50, 40);

            renderer.Render(form, bmp);
            BitmapComparer.CompareBitmaps("panels_hbox", bmp);
        }
Example #24
0
        public void TakesAScreenshotForAWebPageNonMatch()
        {
            var url      = Directory.GetCurrentDirectory() + "/WebPages/DemoPage2.html";
            var filePath = "pic.png";

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            using (var driver = new ChromeDriver(@"Drivers/"))
            {
                var sut = new ScreenshotProvider(driver);
                sut.SaveScreenshot(url, filePath);
            }

            var bitmapComparer = new BitmapComparer();
            var result         = bitmapComparer.AreSame(@"pic.png", @"OldImages/pic.png");

            Assert.IsFalse(result);
        }
Example #25
0
        private void Prehash(string dir, WorkWindow wwin, string fname)
        {
            IEnumerable <string> files =
                Directory.EnumerateFiles(dir, "*", SearchOption.AllDirectories)
                .Where(file => file.EndsWith(".png") || file.EndsWith(".jpg") || file.EndsWith(".jpeg"));

            ParallelOptions opts = new ParallelOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount - 1
            };

            int idx   = 0;
            int total = files.Count();

            Parallel.ForEach(files, opts, (file) =>
            {
                wwin.SetPBarScore(idx, total);
                wwin.SetSecondaryMessage($"BUILDING CACHE...\n  [{idx}] out of [{files.Count()}]");
                BitmapComparer.CacheDiff(file);
                idx++;
            });

            BitmapComparer.SaveDiffCacheToDisk(fname);
        }
Example #26
0
        public void It_should_render_viewports()
        {
            var renderer = new BitmapRenderer();

            var stack = new Stack();

            stack.AddComponent(new Panel
            {
                Width           = 100,
                Height          = 100,
                Border          = Border.Parse("1 #808080"),
                BackgroundColor = Color.LightBlue,
                BorderRadius    = BorderRadius.Parse("25")
            });
            stack.AddComponent(new Viewport
            {
                Alignment = Alignment.Parse("center left"),
                Width     = 10,
                Inner     = new Panel
                {
                    Width           = 40,
                    Height          = 40,
                    Border          = Border.Parse("1 #808080"),
                    BackgroundColor = Color.White,
                    BorderRadius    = BorderRadius.Parse("20")
                },
                ContentAlignment = Alignment.Parse("center right")
            });
            stack.AddComponent(new Viewport
            {
                Alignment = Alignment.Parse("top center"),
                Height    = 10,
                Inner     = new Panel
                {
                    Width           = 40,
                    Height          = 40,
                    Border          = Border.Parse("1 #808080"),
                    BackgroundColor = Color.White,
                    BorderRadius    = BorderRadius.Parse("20")
                },
                ContentAlignment = Alignment.Parse("bottom center")
            });
            stack.AddComponent(new Viewport
            {
                Alignment = Alignment.Parse("center right"),
                Width     = 10,
                Inner     = new Panel
                {
                    Width           = 40,
                    Height          = 40,
                    Border          = Border.Parse("1 #808080"),
                    BackgroundColor = Color.White,
                    BorderRadius    = BorderRadius.Parse("20")
                },
                ContentAlignment = Alignment.Parse("center left")
            });
            stack.AddComponent(new Viewport
            {
                Alignment = Alignment.Parse("bottom center"),
                Height    = 10,
                Inner     = new Panel
                {
                    Width           = 40,
                    Height          = 40,
                    Border          = Border.Parse("1 #808080"),
                    BackgroundColor = Color.White,
                    BorderRadius    = BorderRadius.Parse("20")
                },
                ContentAlignment = Alignment.Parse("top center")
            });
            stack.AddComponent(new Viewport
            {
                Alignment  = Alignment.Parse("center center"),
                ClipMargin = Spacer.Parse("3 1"),
                Inner      = new Panel
                {
                    Width           = 40,
                    Height          = 40,
                    BackgroundColor = Color.White,
                    Border          = Border.Parse("1 #808080"),
                    BorderRadius    = BorderRadius.Parse("20")
                },
                ContentAlignment = Alignment.Parse("center center")
            });
            var form = new Form(stack);

            var bmp = renderer.Render(form);

            BitmapComparer.CompareBitmaps("viewport", bmp);
        }
        public void CompareThrowsWhenSecondImageIsNull()
        {
            var target = new BitmapComparer(null);

            Should.Throw <ArgumentNullException>(() => target.Compare(FirstImage, null));
        }
 private List<WriteableBitmap> DeduplicateTemps(List<WriteableBitmap> tempTiles)
 {
     var existingFrames = RipAllFrames();
     var comparer = new BitmapComparer();
     return tempTiles
         .Distinct(comparer)
         .Except(existingFrames.Keys, comparer)
         .ToList();
 }
Example #29
0
        public void It_should_render_text()
        {
            var renderer = new BitmapRenderer();
            var content  = new HBox {
                Width = SizeUnit.Unlimited
            };

            content.AddComponent(new Panel
            {
                Width           = 100,
                Height          = SizeUnit.Unlimited,
                BackgroundColor = Color.Yellow,
                Margin          = new Spacer(1),
                Border          = new Border(1, Color.White),
                Padding         = new Spacer(2),
                Inner           = new Label
                {
                    TextColor = Color.Red,
                    Font      = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic),
                    Text      = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?"
                }
            });

            content.AddComponent(new Panel
            {
                Width           = 100,
                Height          = SizeUnit.Unlimited,
                BackgroundColor = Color.DarkSeaGreen,
                Margin          = new Spacer(1),
                Border          = new Border(1, Color.White),
                Padding         = new Spacer(2),
                Inner           = new Link
                {
                    TextColor = Color.Blue,
                    Font      = new FontInfo(TestFontFamily.Serif, 14, FontInfoStyle.Bold),
                    Text      = "How are you doing today?",
                    Uri       = "http://google.com"
                }
            });

            var textBox = new TextBox();

            textBox.AddComponent(new Label {
                Text = "Hello!\n", TextColor = Color.Green, Font = new FontInfo(TestFontFamily.Monospace, 20, FontInfoStyle.Underline)
            });
            textBox.AddComponent(new Label {
                Text = "Hi Bob, nice to see you after", TextColor = Color.Black, Font = new FontInfo(TestFontFamily.SansSerif, 10)
            });
            textBox.AddComponent(new Label {
                Text = "20", TextColor = Color.Red, Font = new FontInfo(TestFontFamily.SansSerif, 10, FontInfoStyle.Bold)
            });
            textBox.AddComponent(new Label {
                Text = "years!\n", TextColor = Color.Black, Font = new FontInfo(TestFontFamily.SansSerif, 10)
            });
            textBox.AddComponent(new Label {
                Text = "I'm sure you'd love to see my new", TextColor = Color.Black, Font = new FontInfo(TestFontFamily.SansSerif, 10)
            });
            textBox.AddComponent(new Link {
                Text = "web", TextColor = Color.Blue, Font = new FontInfo(TestFontFamily.SansSerif, 12, FontInfoStyle.Italic), Uri = "http://google.com"
            });
            textBox.AddComponent(new Link {
                Text = "site", TextColor = Color.Green, TextContinuation = true, Font = new FontInfo(TestFontFamily.SansSerif, 12, FontInfoStyle.Italic), Uri = "http://google.com"
            });
            content.AddComponent(new Panel
            {
                Width           = SizeUnit.Unlimited,
                Height          = SizeUnit.Unlimited,
                BackgroundColor = Color.LightYellow,
                Margin          = new Spacer(1),
                Border          = new Border(1, Color.White),
                Padding         = new Spacer(2),
                Inner           = textBox
            });

            var form = new Form(content);

            var bmp = new Bitmap(320, 400);

            renderer.Render(form, bmp);
            BitmapComparer.CompareBitmaps("text_box", bmp);
        }
Example #30
0
        public void It_should_render_text_with_alignments()
        {
            var renderer = new BitmapRenderer();

            var labelBox = new HBox {
                Width = SizeUnit.Unlimited
            };

            foreach (var align in new[] { TextAlignment.Left, TextAlignment.Right, TextAlignment.Center, TextAlignment.Justify })
            {
                labelBox.AddComponent(new Panel
                {
                    Width           = 100,
                    Height          = SizeUnit.Unlimited,
                    BackgroundColor = Color.Yellow,
                    Margin          = new Spacer(1),
                    Border          = new Border(1, Color.White),
                    Padding         = new Spacer(2),
                    Inner           = new Label
                    {
                        Width         = SizeUnit.Unlimited,
                        TextColor     = Color.Red,
                        TextAlignment = align,
                        Font          = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic),
                        Text          = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?"
                    }
                });
            }

            var areaBox = new HBox {
                Width = SizeUnit.Unlimited
            };

            foreach (var align in new[] { TextAlignment.Left, TextAlignment.Right, TextAlignment.Center, TextAlignment.Justify })
            {
                var textBox = new TextBox
                {
                    Width         = SizeUnit.Unlimited,
                    TextAlignment = align
                };
                textBox.AddComponent(new Label
                {
                    TextColor = Color.Red,
                    Text      = "Hi Bob!",
                    Font      = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic)
                });

                textBox.AddComponent(new Link
                {
                    TextColor = Color.Black,
                    Text      = "Check out this: ",
                    Font      = new FontInfo(TestFontFamily.Serif, 12, FontInfoStyle.Regular)
                });
                textBox.AddComponent(new Link
                {
                    TextColor = Color.Purple,
                    Text      = "great link!!!",
                    Font      = new FontInfo(TestFontFamily.Serif, 8, FontInfoStyle.Underline),
                    Uri       = "http://google.com"
                });
                areaBox.AddComponent(new Panel
                {
                    Width           = 100,
                    Height          = SizeUnit.Unlimited,
                    BackgroundColor = Color.Green,
                    Margin          = new Spacer(1),
                    Border          = new Border(1, Color.White),
                    Padding         = new Spacer(2),
                    Inner           = textBox
                });
            }

            var content = new VBox {
                Width = SizeUnit.Unlimited
            };

            content.AddComponent(labelBox);
            content.AddComponent(areaBox);

            var form = new Form(content);

            var bmp = new Bitmap(400, 400);

            renderer.Render(form, bmp);
            BitmapComparer.CompareBitmaps("text_box_align", bmp);
        }
Example #31
0
        public void CompareThrowsWhenSecondImageIsNull()
        {
            var target = new BitmapComparer(null);

            target.Compare(FirstImage, null);
        }