/// <summary> /// Creates a reference to the sprite / inlined version of the desired image including special attributes. /// </summary> /// <param name="virtualPath">The relative path of the image to be displayed</param> /// <param name="htmlAttributes">Html Attributes of IDictionary form</param> /// <returns>Image tag.</returns> public static IHtmlString Image(string virtualPath, IDictionary <string, object> htmlAttributes) { ImageOptimizations.EnsureInitialized(); TagBuilder htmlTag = new TagBuilder("img"); htmlTag.MergeAttributes(htmlAttributes); HttpContextBase httpContext = new HttpContextWrapper(HttpContext.Current); string localSpriteDirectory = Path.GetDirectoryName(httpContext.Server.MapPath(virtualPath)); if (ImageOptimizations.LinkCompatibleCssFileName(httpContext.Request.Browser, localSpriteDirectory) == null) { htmlTag.MergeAttribute("src", ResolveUrl(virtualPath)); return(new HtmlString(htmlTag.ToString(TagRenderMode.SelfClosing))); } else { htmlTag.AddCssClass(ImageOptimizations.MakeCssClassName(virtualPath)); htmlTag.MergeAttribute("src", ResolveUrl(ImageOptimizations.GetBlankImageSource(httpContext.Request.Browser))); return(new HtmlString(htmlTag.ToString(TagRenderMode.SelfClosing))); } }