public void TestSpriting() { var loader = new TestLoader(); var spritingSettings = new SpritingSettings { SpriteSizeLimit = 100 * 100, SpriteColorLimit = 4096, ImageOptimizationDisabled = true, ImageQuantizationDisabled = true }; var generator = new SpriteGenerator( new CssImageExtractor(new CssSelectorAnalyzer()), path => new SpriteManager( spritingSettings, loader, bytes => "/url", new NullOptimizer() ) ); var package = generator.GenerateFromCss( ".a { background: url(a.png) no-repeat; width: 10px; height: 10px; }\n" + ".b { background: url(b.png) no-repeat; width: 10px; height: 10px; }", "/test.css"); package.Exceptions.ShouldBeEmpty(); package.GeneratedCss.ShouldEqual( ".a { background: url(/url) no-repeat; width: 10px; height: 10px; ;background-position: -0px 0;}\n" + ".b { background: url(/url) no-repeat; width: 10px; height: 10px; ;background-position: -11px 0;}" ); var s = new MemoryStream(package.Sprites[0].Image); using (var bmp = new Bitmap(s)) { bmp.Width.ShouldEqual(22); bmp.Height.ShouldEqual(10); } }
public void TestSpriting() { var loader = new TestLoader(); var spritingSettings = new SpritingSettings { SpriteSizeLimit = 100 * 100, SpriteColorLimit = 4096, ImageOptimizationDisabled = true, ImageQuantizationDisabled = true }; var generator = new SpriteGenerator( new CssImageExtractor(new CssSelectorAnalyzer()), path => new SpriteManager( spritingSettings, loader, bytes => "/url", new NullOptimizer() ) ); var package = generator.GenerateFromCss( ".a { background: url(a.png) no-repeat; width: 10px; height: 10px; }\n" + ".b { background: url(b.png) no-repeat; width: 10px; height: 10px; }", "/test.css"); package.Exceptions.ShouldBeEmpty(); package.GeneratedCss.ShouldEqual( ".a { background: url(/url) no-repeat; width: 10px; height: 10px; ;background-position: -0px 0;}\n" + ".b { background: url(/url) no-repeat; width: 10px; height: 10px; ;background-position: -11px 0;}" ); var s = new MemoryStream(package.Sprites[0].Image); using(var bmp = new Bitmap(s)) { bmp.Width.ShouldEqual(22); bmp.Height.ShouldEqual(10); } }