Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ImageResource.cs
1using System.Threading.Tasks;
2using System.Xml;
3using SkiaSharp;
4using Waher.Content;
6
8{
12 public class ImageResource : Image
13 {
14 private StringAttribute resource;
15
22 : base(Document, Parent)
23 {
24 }
25
29 public override string LocalName => "ImageResource";
30
35 {
36 get => this.resource;
37 set => this.resource = value;
38 }
39
44 public override Task FromXml(XmlElement Input)
45 {
46 this.resource = new StringAttribute(Input, "resource", this.Document);
47 return base.FromXml(Input);
48 }
49
54 public override void ExportAttributes(XmlWriter Output)
55 {
56 base.ExportAttributes(Output);
57
58 this.resource?.Export(Output);
59 }
60
67 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
68 {
69 return new ImageResource(Document, Parent);
70 }
71
76 public override void CopyContents(ILayoutElement Destination)
77 {
78 base.CopyContents(Destination);
79
80 if (Destination is ImageResource Dest)
81 Dest.resource = this.resource?.CopyIfNotPreset(Destination.Document);
82 }
83
90 protected override async Task<SKImage> LoadImage(DrawingState State)
91 {
92 string ResourceName = await this.resource.Evaluate(State.Session, string.Empty);
93 if (!string.IsNullOrEmpty(ResourceName))
94 {
95 byte[] Bin = Resources.LoadResource(ResourceName);
96 SKBitmap Bitmap = SKBitmap.Decode(Bin);
97 return SKImage.FromBitmap(Bitmap);
98 }
99 else
100 return null;
101 }
102
107 public override void ExportStateAttributes(XmlWriter Output)
108 {
109 base.ExportStateAttributes(Output);
110
111 this.resource?.ExportState(Output);
112 }
113
114 }
115}
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:15
static byte[] LoadResource(string ResourceName)
Loads a resource from an embedded resource.
Definition: Resources.cs:61
Contains a 2D layout document.
void Export(XmlWriter Output)
Exports the attribute.
Definition: Attribute.cs:187
void ExportState(XmlWriter Output)
Exports the state of the attribute.
Definition: Attribute.cs:199
StringAttribute CopyIfNotPreset(Layout2DDocument ForDocument)
Copies the attribute object if undefined, or defined by an expression. Returns a reference to itself,...
Variables Session
Current session.
Definition: DrawingState.cs:91
Abstract base class for images.
Definition: Image.cs:12
An image defined in an embedded resource.
override string LocalName
Local name of type of element.
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
Creates a new instance of the layout element.
ImageResource(Layout2DDocument Document, ILayoutElement Parent)
An image defined in an embedded resource.
override async Task< SKImage > LoadImage(DrawingState State)
Loads the image defined by the element.
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
Layout2DDocument Document
Layout document.
Base interface for all layout elements.
Layout2DDocument Document
Layout document.