AngleSharp by AngleSharp

<PackageReference Include="AngleSharp" Version="0.9.9" />

.NET API 1,224,192 bytes

 HtmlImageElement

Represents the image element.
using AngleSharp.Dom.Css; using AngleSharp.Dom.Events; using AngleSharp.Extensions; using AngleSharp.Html; using AngleSharp.Network; using AngleSharp.Network.RequestProcessors; namespace AngleSharp.Dom.Html { internal sealed class HtmlImageElement : HtmlElement, IHtmlImageElement, IHtmlElement, IElement, INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode, IElementCssInlineStyle, IGlobalEventHandlers, ILoadableElement { private readonly ImageRequestProcessor _request; public IDownload CurrentDownload => _request?.Download; public string ActualSource { get { if (!IsCompleted) return string.Empty; return _request.Source; } } public string SourceSet { get { return this.GetOwnAttribute(AttributeNames.SrcSet); } set { this.SetOwnAttribute(AttributeNames.SrcSet, value, false); } } public string Sizes { get { return this.GetOwnAttribute(AttributeNames.Sizes); } set { this.SetOwnAttribute(AttributeNames.Sizes, value, false); } } public string Source { get { return this.GetUrlAttribute(AttributeNames.Src); } set { this.SetOwnAttribute(AttributeNames.Src, value, false); } } public string AlternativeText { get { return this.GetOwnAttribute(AttributeNames.Alt); } set { this.SetOwnAttribute(AttributeNames.Alt, value, false); } } public string CrossOrigin { get { return this.GetOwnAttribute(AttributeNames.CrossOrigin); } set { this.SetOwnAttribute(AttributeNames.CrossOrigin, value, false); } } public string UseMap { get { return this.GetOwnAttribute(AttributeNames.UseMap); } set { this.SetOwnAttribute(AttributeNames.UseMap, value, false); } } public int DisplayWidth { get { return this.GetOwnAttribute(AttributeNames.Width).ToInteger(OriginalWidth); } set { this.SetOwnAttribute(AttributeNames.Width, value.ToString(), false); } } public int DisplayHeight { get { return this.GetOwnAttribute(AttributeNames.Height).ToInteger(OriginalHeight); } set { this.SetOwnAttribute(AttributeNames.Height, value.ToString(), false); } } public int OriginalWidth => _request?.Width ?? 0; public int OriginalHeight => _request?.Height ?? 0; public bool IsCompleted { get { ImageRequestProcessor request = _request; if (request == null) return false; return request.IsReady; } } public bool IsMap { get { return this.GetBoolAttribute(AttributeNames.IsMap); } set { this.SetBoolAttribute(AttributeNames.IsMap, value); } } static HtmlImageElement() { Element.RegisterCallback(AttributeNames.Src, delegate(HtmlImageElement element, string value) { element.UpdateSource(); }); Element.RegisterCallback(AttributeNames.SrcSet, delegate(HtmlImageElement element, string value) { element.UpdateSource(); }); Element.RegisterCallback(AttributeNames.Sizes, delegate(HtmlImageElement element, string value) { element.UpdateSource(); }); Element.RegisterCallback(AttributeNames.CrossOrigin, delegate(HtmlImageElement element, string value) { element.UpdateSource(); }); } public HtmlImageElement(Document owner, string prefix = null) : base(owner, TagNames.Img, prefix, NodeFlags.SelfClosing | NodeFlags.Special) { _request = ImageRequestProcessor.Create(this); } internal override void SetupElement() { base.SetupElement(); UpdateSource(); } private void UpdateSource() { Url imageCandidate = this.GetImageCandidate(); this.Process(_request, imageCandidate); } } }