public void BasicTest(double dpi, double fgScale, string bg, string fg, int exWidth, int exHeight)
            {
                var info = new ResizeImageInfo();

                info.Filename           = "images/" + bg;
                info.ForegroundFilename = "images/" + fg;
                info.ForegroundScale    = fgScale;
                info.IsAppIcon          = true;

                var tools   = new SkiaSharpAppIconTools(info, Logger);
                var dpiPath = new DpiPath("", (decimal)dpi);

                tools.Resize(dpiPath, DestinationFilename);

                AssertFileSize(DestinationFilename, exWidth, exHeight);
            }
            public void BasicTest(double dpi, double fgScale, string bg, string fg)
            {
                var info = new SharedImageInfo();

                info.Filename           = "images/" + bg;
                info.ForegroundFilename = "images/" + fg;
                info.ForegroundScale    = fgScale;
                info.IsAppIcon          = true;

                var tools   = new SkiaSharpAppIconTools(info, Logger);
                var dpiPath = new DpiPath("", (decimal)dpi);

                tools.Resize(dpiPath, DestinationFilename);

                //File.Copy(DestinationFilename, $"output-{dpi}-{fgScale}-{bg}-{fg}.png", true);
            }
Beispiel #3
0
            public void BasicWithDownScaleReturnsDownScaledSize()
            {
                var info = new SharedImageInfo();

                info.Filename = "images/camera.png";
                var tools   = new SkiaSharpBitmapTools(info, Logger);
                var dpiPath = new DpiPath("", 0.5m);

                tools.Resize(dpiPath, DestinationFilename);

                using var resultImage = SKBitmap.Decode(DestinationFilename);
                Assert.Equal(896, resultImage.Width);
                Assert.Equal(896, resultImage.Height);

                using var pixmap = resultImage.PeekPixels();
                Assert.Equal(SKColors.Empty, pixmap.GetPixelColor(10, 10));
                Assert.Equal(SKColors.White, pixmap.GetPixelColor(175, 175));
            }
            public void BasicNoScaleReturnsOriginalSize()
            {
                var info = new SharedImageInfo();

                info.Filename = "images/camera.svg";
                var tools   = new SkiaSharpSvgTools(info, Logger);
                var dpiPath = new DpiPath("", 1);

                tools.Resize(dpiPath, DestinationFilename);

                using var resultImage = SKBitmap.Decode(DestinationFilename);
                Assert.Equal(1792, resultImage.Width);
                Assert.Equal(1792, resultImage.Height);

                using var pixmap = resultImage.PeekPixels();
                Assert.Equal(SKColors.Empty, pixmap.GetPixelColor(10, 10));
                Assert.Equal(SKColors.White, pixmap.GetPixelColor(350, 350));
            }
            public void ColorsInCssCanBeUsed()
            {
                var info = new ResizeImageInfo();

                info.Filename = "images/not_working.svg";
                var tools   = new SkiaSharpSvgTools(info, Logger);
                var dpiPath = new DpiPath("", 1);

                tools.Resize(dpiPath, DestinationFilename);

                using var resultImage = SKBitmap.Decode(DestinationFilename);
                Assert.Equal(24, resultImage.Width);
                Assert.Equal(24, resultImage.Height);

                using var pixmap = resultImage.PeekPixels();
                Assert.Equal(SKColors.Empty, pixmap.GetPixelColor(2, 2));
                Assert.Equal(0xFF71559B, pixmap.GetPixelColor(2, 6));
            }
Beispiel #6
0
            public void ColorizedWithNamedReturnsColored()
            {
                var info = new SharedImageInfo();

                info.Filename  = "images/camera.png";
                info.TintColor = Color.FromName("Red");
                var tools   = new SkiaSharpBitmapTools(info, Logger);
                var dpiPath = new DpiPath("", 1);

                tools.Resize(dpiPath, DestinationFilename);

                using var resultImage = SKBitmap.Decode(DestinationFilename);
                Assert.Equal(1792, resultImage.Width);
                Assert.Equal(1792, resultImage.Height);

                using var pixmap = resultImage.PeekPixels();
                Assert.Equal(SKColors.Empty, pixmap.GetPixelColor(10, 10));
                Assert.Equal(SKColors.Red, pixmap.GetPixelColor(350, 350));
            }
            public void DiffPropoprtionWithoutBaseUseBackgroundSize(double dpi, double fgScale, string bg, string fg, int exWidth, int exHeight)
            {
                var info = new ResizeImageInfo
                {
                    Filename           = "images/" + bg,
                    ForegroundFilename = "images/" + fg,
                    ForegroundScale    = fgScale,
                    IsAppIcon          = true,
                    Color = SKColors.Orange,
                };

                var tools   = new SkiaSharpAppIconTools(info, Logger);
                var dpiPath = new DpiPath("", (decimal)dpi);

                tools.Resize(dpiPath, DestinationFilename);

                AssertFileSize(DestinationFilename, exWidth, exHeight);
                AssertFileMatches(DestinationFilename, new object[] { dpi, fgScale, bg, fg });
            }
Beispiel #8
0
            public void BasicWithColorsKeepsColors()
            {
                var info = new SharedImageInfo();

                info.Filename = "images/camera_color.png";
                var tools   = new SkiaSharpBitmapTools(info, Logger);
                var dpiPath = new DpiPath("", 1);

                tools.Resize(dpiPath, DestinationFilename);

                using var resultImage = SKBitmap.Decode(DestinationFilename);
                Assert.Equal(256, resultImage.Width);
                Assert.Equal(256, resultImage.Height);

                using var pixmap = resultImage.PeekPixels();
                Assert.Equal(SKColors.Empty, pixmap.GetPixelColor(10, 10));
                Assert.Equal(SKColors.Red, pixmap.GetPixelColor(37, 137));
                Assert.Equal(SKColors.Lime, pixmap.GetPixelColor(81, 137));
                Assert.Equal(SKColors.Blue, pixmap.GetPixelColor(125, 137));
            }
Beispiel #9
0
            public void ColorizedWithAlphaWithColorsReplacesColors()
            {
                var info = new SharedImageInfo();

                info.Filename  = "images/camera_color.png";
                info.TintColor = Color.FromArgb(127, Color.Red);
                var tools   = new SkiaSharpBitmapTools(info, Logger);
                var dpiPath = new DpiPath("", 1);

                tools.Resize(dpiPath, DestinationFilename);

                using var resultImage = SKBitmap.Decode(DestinationFilename);
                Assert.Equal(256, resultImage.Width);
                Assert.Equal(256, resultImage.Height);

                using var pixmap = resultImage.PeekPixels();
                Assert.Equal(SKColors.Empty, pixmap.GetPixelColor(10, 10));
                Assert.Equal(SKColors.Red.WithAlpha(127), pixmap.GetPixelColor(37, 137));
                Assert.Equal(SKColors.Red.WithAlpha(127), pixmap.GetPixelColor(81, 137));
                Assert.Equal(SKColors.Red.WithAlpha(127), pixmap.GetPixelColor(125, 137));
            }
Beispiel #10
0
            public void WithBaseSizeResizes()
            {
                var info = new SharedImageInfo();

                info.Filename = "images/camera_color.png";
                info.BaseSize = new Size(512, 512);
                var tools   = new SkiaSharpBitmapTools(info, Logger);
                var dpiPath = new DpiPath("", 1);

                tools.Resize(dpiPath, DestinationFilename);

                using var resultImage = SKBitmap.Decode(DestinationFilename);
                Assert.Equal(512, resultImage.Width);
                Assert.Equal(512, resultImage.Height);

                using var pixmap = resultImage.PeekPixels();
                Assert.Equal(SKColors.Empty, pixmap.GetPixelColor(10, 10));
                Assert.Equal(SKColors.Red, pixmap.GetPixelColor(74, 274));
                Assert.Equal(SKColors.Lime, pixmap.GetPixelColor(162, 274));
                Assert.Equal(SKColors.Blue, pixmap.GetPixelColor(250, 274));
            }
            public void WithBaseSizeAndScaleResizes()
            {
                var info = new ResizeImageInfo();

                info.Filename = "images/camera_color.svg";
                info.BaseSize = new Size(512, 512);
                var tools   = new SkiaSharpSvgTools(info, Logger);
                var dpiPath = new DpiPath("", 0.5m);

                tools.Resize(dpiPath, DestinationFilename);

                using var resultImage = SKBitmap.Decode(DestinationFilename);
                Assert.Equal(256, resultImage.Width);
                Assert.Equal(256, resultImage.Height);

                using var pixmap = resultImage.PeekPixels();
                Assert.Equal(SKColors.Empty, pixmap.GetPixelColor(10, 10));
                Assert.Equal(SKColors.Red, pixmap.GetPixelColor(37, 137));
                Assert.Equal(SKColors.Lime, pixmap.GetPixelColor(81, 137));
                Assert.Equal(SKColors.Blue, pixmap.GetPixelColor(125, 137));
            }
Beispiel #12
0
            public void ReturnsNullOnInvalidPlatform(string platform)
            {
                var paths = DpiPath.GetOriginal(platform);

                Assert.Null(paths);
            }
Beispiel #13
0
            public void MatchesAnyCase(string platform)
            {
                var paths = DpiPath.GetOriginal(platform);

                Assert.NotNull(paths);
            }
Beispiel #14
0
            public void ReturnsCorrectScale(string platform, decimal scale)
            {
                var paths = DpiPath.GetOriginal(platform);

                Assert.Equal(scale, paths.Scale);
            }
Beispiel #15
0
            public void ReturnsCorrectFolder(string platform, string folder)
            {
                var paths = DpiPath.GetOriginal(platform);

                Assert.Equal(folder, paths.Path);
            }