本文整理汇总了C#中RequestReduce.Reducer.BackgroundImageClass类的典型用法代码示例。如果您正苦于以下问题:C# BackgroundImageClass类的具体用法?C# BackgroundImageClass怎么用?C# BackgroundImageClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BackgroundImageClass类属于RequestReduce.Reducer命名空间,在下文中一共展示了BackgroundImageClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddImage
public void AddImage(BackgroundImageClass image)
{
var imageBytes = webClientWrapper.DownloadBytes(image.ImageUrl);
Bitmap bitmap = null;
using (var originalBitmap = new Bitmap(new MemoryStream(imageBytes)))
{
using (var writer = new SpriteWriter(image.Width ?? originalBitmap.Width, image.Height ?? originalBitmap.Height))
{
var width = image.Width ?? originalBitmap.Width;
if (width > originalBitmap.Width)
width = originalBitmap.Width;
var height = image.Height ?? originalBitmap.Height;
if (height > originalBitmap.Height)
height = originalBitmap.Height;
var x = image.XOffset.Offset < 0 ? Math.Abs(image.XOffset.Offset) : 0;
var y = image.YOffset.Offset < 0 ? Math.Abs(image.YOffset.Offset) : 0;
writer.WriteImage(originalBitmap.Clone(new Rectangle(x, y, width, height), originalBitmap.PixelFormat));
bitmap = writer.SpriteImage;
if ((originalBitmap.Width * originalBitmap.Height) > (bitmap.Width * bitmap.Height))
Size += writer.GetBytes("image/png").Length;
else
Size += imageBytes.Length;
}
}
images.Add(bitmap);
Width += bitmap.Width;
if (Height < bitmap.Height) Height = bitmap.Height;
}
示例2: InheritMissingProperties
private static void InheritMissingProperties(BackgroundImageClass derrivableClass, BackgroundImageClass imageClass)
{
if (DerivableHasMissingProperty(derrivableClass, imageClass, PropertyCompletion.HasYOffset))
imageClass.YOffset = derrivableClass.YOffset;
if (DerivableHasMissingProperty(derrivableClass, imageClass, PropertyCompletion.HasXOffset))
imageClass.XOffset = derrivableClass.XOffset;
if (DerivableHasMissingProperty(derrivableClass, imageClass, PropertyCompletion.HasRepeat))
imageClass.Repeat = derrivableClass.Repeat;
if (DerivableHasMissingProperty(derrivableClass, imageClass, PropertyCompletion.HasImage))
imageClass.ImageUrl = derrivableClass.ImageUrl;
if (DerivableHasMissingProperty(derrivableClass, imageClass, PropertyCompletion.HasPaddingBottom))
imageClass.PaddingBottom = derrivableClass.PaddingBottom;
if (DerivableHasMissingProperty(derrivableClass, imageClass, PropertyCompletion.HasPaddingTop))
imageClass.PaddingTop = derrivableClass.PaddingTop;
if (DerivableHasMissingProperty(derrivableClass, imageClass, PropertyCompletion.HasPaddingLeft))
imageClass.PaddingLeft = derrivableClass.PaddingLeft;
if (DerivableHasMissingProperty(derrivableClass, imageClass, PropertyCompletion.HasPaddingRight))
imageClass.PaddingRight = derrivableClass.PaddingRight;
if (DerivableHasMissingProperty(derrivableClass, imageClass, PropertyCompletion.HasWidth))
imageClass.ExplicitWidth = derrivableClass.ExplicitWidth;
if (DerivableHasMissingProperty(derrivableClass, imageClass, PropertyCompletion.HasHeight))
imageClass.ExplicitHeight = derrivableClass.ExplicitHeight;
}
示例3: ExtractImageUrls
public IEnumerable<BackgroundImageClass> ExtractImageUrls(string cssContent)
{
var finalUrls = new List<BackgroundImageClass>();
var draftUrls = new List<BackgroundImageClass>();
var classCounter = 0;
foreach (var classMatch in classPattern.Matches(cssContent))
{
var imageClass = new BackgroundImageClass(classMatch.ToString(), ++classCounter);
if (!ShouldFlatten(imageClass)) continue;
if (!IsComplete(imageClass) && ShouldFlatten(imageClass))
{
var workList = new List<BackgroundImageClass>();
for (var n = draftUrls.Count - 1; n > -1; n--)
{
var selectors = draftUrls[n].Selector.Split(new [] {','});
var targetSelectors = imageClass.Selector.Split(new[] { ',' });
foreach (var selector in selectors)
{
if (targetSelectors
.Any(targetSelector => cssSelectorAnalyzer.IsInScopeOfTarget(targetSelector.Trim(), selector.Trim())))
workList.Add(draftUrls[n]);
}
}
workList.Sort(selectorComparer);
foreach (var cls in workList.Where(cls => !IsComplete(imageClass)))
InheritMissingProperties(cls, imageClass);
}
draftUrls.Add(imageClass);
if (CanSprite(imageClass))
finalUrls.Add(imageClass);
}
return finalUrls;
}
示例4: SpritedImage
public SpritedImage(int averageColor, BackgroundImageClass cssClass, Bitmap image)
{
AverageColor = averageColor;
CssClass = cssClass;
Image = image;
Position = -1;
}
示例5: Add
public virtual void Add(BackgroundImageClass image)
{
var imageKey = new ImageMetadata(image);
if (RRContainer.Current.GetAllInstances<IFilter>().Where(x => x is SpriteFilter).FirstOrDefault(y => y.IgnoreTarget(new SpriteFilterContext(image))) != null || spriteList.ContainsKey(imageKey))
return;
SpritedImage spritedImage;
try
{
spritedImage = SpriteContainer.AddImage(image);
}
catch (InvalidOperationException ex)
{
var message = string.Format("There were errors reducing {0}", image.ImageUrl);
var wrappedException =
new ApplicationException(message, ex);
RRTracer.Trace(message);
RRTracer.Trace(ex.ToString());
if (Registry.CaptureErrorAction != null)
Registry.CaptureErrorAction(wrappedException);
return;
}
spriteList.Add(imageKey, spritedImage);
if (SpriteContainer.Size >= config.SpriteSizeLimit || (SpriteContainer.Colors >= config.SpriteColorLimit && !config.ImageQuantizationDisabled && !config.ImageOptimizationDisabled))
Flush();
}
示例6: Add
public virtual void Add(BackgroundImageClass image)
{
var imageKey = new ImageMetadata(image);
if (spriteList.ContainsKey(imageKey))
return;
SpritedImage spritedImage = null;
try
{
spritedImage = SpriteContainer.AddImage(image);
}
catch (InvalidOperationException ex)
{
var message = string.Format("There were errors reducing {0}", image.ImageUrl);
var wrappedException =
new ApplicationException(message, ex);
RRTracer.Trace(message);
RRTracer.Trace(ex.ToString());
if (RequestReduceModule.CaptureErrorAction != null)
RequestReduceModule.CaptureErrorAction(wrappedException);
return;
}
spriteList.Add(imageKey, spritedImage);
if (SpriteContainer.Size >= config.SpriteSizeLimit || (SpriteContainer.Colors >= config.SpriteColorLimit && !config.ImageQuantizationDisabled && !config.ImageOptimizationDisabled))
Flush();
}
示例7: ImageMetadata
public virtual Sprite this[BackgroundImageClass image]
{
get
{
var imageKey = new ImageMetadata(image);
return spriteList.ContainsKey(imageKey) ? spriteList[imageKey] : null;
}
}
示例8: DerivableHasMissingProperty
private static bool DerivableHasMissingProperty(BackgroundImageClass derrivableClass, BackgroundImageClass imageClass, PropertyCompletion property)
{
if ((imageClass.PropertyCompletion & property) != property && (derrivableClass.PropertyCompletion & property) == property)
{
imageClass.PropertyCompletion = imageClass.PropertyCompletion | property;
return true;
}
return false;
}
示例9: WillLeaveImageUrlNullIfBackgroundImageUrlIsDataUri
public void WillLeaveImageUrlNullIfBackgroundImageUrlIsDataUri()
{
var css =
@"
.LocalNavigation .TabOn,.LocalNavigation .TabOn:hover {
background-image: url(""data:image/png;base64,d09GRgABAAAAAGGwABAAAAAAmXgAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABbAAAABsAAAAcX1JF+UdERUYAAAGIAAAAHgAAACABCwAET1MvMgAAAagAAABeAAAAYJ95kIljbWFwAAACCAAAAYIAAAHSJ4j+bmN2dCAAAAOMAAAAOgAAADoKdA1FZnBnbQAAA8gAAAGxAAACZQ+0L6dnYXNwAAAFfAAAAAgAAAAIAAAAEGdseWYAAAWEAABUbAAAiCQqo7XWaGVhZAAAWfAAAAAxAAAANvtKIUxoaGVhAABaJAAAACAAAAAkDcQFa2htdHgAAFpEAAACGQAAA3ija1fqbG9jYQAAXGAAAAG+AAABvjB3Ef5tYXhwAABeIAAAACAAAAAgAgIDGG5hbWUAAF5AAAABAQAAAc4mzUHdcG9zdAAAX0QAAAGeAAACSJtdU59wcmVwAABg5AAAAMoAAAFgbSDjunjaY2BgYGQAgpOd+YYg+tST7GQonQIARx4G7QB42mNgZGBg4ANiCQYQYGJgBMK7QMwC5jEAAA3JARAAAHjaY2BmsWScwMDKwMA6i9WYgYFRHkIzX2RIY/zEwMDEzcbGzMHCxMTygIFpvQODQjQDA4MGEDMYOgY7MwAFfrOwpf1LY2BgL2YSUWBgmA+SY/Fi3QakFBgYAZoDDiYAAHjaY2BgYGaAY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Wmu1UNkf/WEUWMdUo26VvCHeCVT46BU9VKyen6Ftar3SPfZD0OY288L7cnu6DZXOOSRGvkA0yQY8fH8jtmhsa5YWBTFuJ7MZsmdYhMXYhp4+hWWlxklnAiToZ+8EFtnGJmh8Q37t84eUFq+wXGtUjo5WIilowkl1lw5Fk92RkSWOepxBX2K0JHpVdtAJfr9YrhFjc4aSfLY1GAhkVPktEdqqo/Go5"");
}";
var testable = new BackgroundImageClass(css, 0);
Assert.Null(testable.ImageUrl);
}
示例10: WillLeaveImageUrlNullIfBackgroundImageUrlIsEmpty
public void WillLeaveImageUrlNullIfBackgroundImageUrlIsEmpty()
{
var css =
@"
.LocalNavigation .TabOn,.LocalNavigation .TabOn:hover {
background-image: url("""");
}";
var testable = new BackgroundImageClass(css, 0);
Assert.Null(testable.ImageUrl);
}
示例11: WillSetImageUrlFromBackgroundImageStyle
public void WillSetImageUrlFromBackgroundImageStyle()
{
var css =
@"
.LocalNavigation .TabOn,.LocalNavigation .TabOn:hover {
background-image: url(""http://i3.social.microsoft.com/contentservice/1f22465a-498c-46f1-83d3-9dad00d8a950/subnav_on_technet.png"");
}";
var testable = new BackgroundImageClass(css, 0);
Assert.Equal("http://i3.social.microsoft.com/contentservice/1f22465a-498c-46f1-83d3-9dad00d8a950/subnav_on_technet.png", testable.ImageUrl);
}
示例12: WillSetImageUrlFromShortcutStyleWhwenLastPropertyWithNoSemicolon
public void WillSetImageUrlFromShortcutStyleWhwenLastPropertyWithNoSemicolon()
{
var css =
@"
.LocalNavigation .TabOn,.LocalNavigation .TabOn:hover {
background: #fff url(""http://i3.social.microsoft.com/contentservice/1f22465a-498c-46f1-83d3-9dad00d8a950/subnav_on_technet.png"") repeat
}";
var testable = new BackgroundImageClass(css, 0);
Assert.Equal("http://i3.social.microsoft.com/contentservice/1f22465a-498c-46f1-83d3-9dad00d8a950/subnav_on_technet.png", testable.ImageUrl);
}
示例13: Add
public virtual Sprite Add(BackgroundImageClass image)
{
var imageKey = new ImageMetadata(image);
if (spriteList.ContainsKey(imageKey))
return spriteList[imageKey];
var currentPositionToReturn = SpriteContainer.Width;
SpriteContainer.AddImage(image);
var sprite = new Sprite(currentPositionToReturn, spriteIndex);
if (SpriteContainer.Size >= config.SpriteSizeLimit)
Flush();
spriteList.Add(imageKey, sprite);
return sprite;
}
示例14: WillSetSecondOffsetAsXOffsetWhenFirstOffsetIsBottom
public void WillSetSecondOffsetAsXOffsetWhenFirstOffsetIsBottom(string statedOffset, PositionMode expectedPositionMode, int expectedOffset)
{
var css =
@"
.LocalNavigation .TabOn,.LocalNavigation .TabOn:hover {{
background: url(""http://i3.social.microsoft.com/contentservice/1f22465a-498c-46f1-83d3-9dad00d8a950/subnav_on_technet.png"") no-repeat;
background-position: bottom {0};
}}";
var testable = new BackgroundImageClass(string.Format(css, statedOffset), "http://server/content/style.css");
Assert.Equal(expectedPositionMode, testable.XOffset.PositionMode);
Assert.Equal(expectedOffset, expectedPositionMode == PositionMode.Direction ? (int)testable.XOffset.Direction : testable.XOffset.Offset);
}
示例15: AddImage
public SpritedImage AddImage(BackgroundImageClass image)
{
var imageBytes = webClientWrapper.DownloadBytes(image.ImageUrl);
Bitmap bitmap;
using (var originalBitmap = new Bitmap(new MemoryStream(imageBytes)))
{
using (var writer = new SpriteWriter(image.Width ?? originalBitmap.Width, image.Height ?? originalBitmap.Height))
{
var width = image.Width ?? originalBitmap.Width;
if (width > originalBitmap.Width)
width = originalBitmap.Width;
var height = image.Height ?? originalBitmap.Height;
if (height > originalBitmap.Height)
height = originalBitmap.Height;
var x = image.XOffset.Offset < 0 ? Math.Abs(image.XOffset.Offset) : 0;
var y = image.YOffset.Offset < 0 ? Math.Abs(image.YOffset.Offset) : 0;
try
{
using (var bm = originalBitmap.Clone(new Rectangle(x, y, width, height), originalBitmap.PixelFormat))
{
writer.WriteImage(bm);
}
}
catch (OutOfMemoryException)
{
throw new InvalidOperationException(string.Format("Unable to Add {0} to Sprite.", image.OriginalImageUrl));
}
bitmap = writer.SpriteImage;
if ((originalBitmap.Width * originalBitmap.Height) > (bitmap.Width * bitmap.Height))
Size += writer.GetBytes("image/png").Length;
else
Size += imageBytes.Length;
}
}
var avgColor = rrConfiguration.IsFullTrust ? GetColors(bitmap) : 0;
var spritedImage = new SpritedImage(avgColor, image, bitmap);
images.Add(spritedImage);
Width += bitmap.Width + 1;
if (Height < bitmap.Height) Height = bitmap.Height;
return spritedImage;
}