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 SkiaSharp;
2using System.Threading.Tasks;
3using System.Xml;
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
48 return base.FromXml(Input);
49 }
50
55 public override void ExportAttributes(XmlWriter Output)
56 {
57 base.ExportAttributes(Output);
58
59 this.resource?.Export(Output);
60 }
61
68 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
69 {
70 return new ImageResource(Document, Parent);
71 }
72
77 public override void CopyContents(ILayoutElement Destination)
78 {
79 base.CopyContents(Destination);
80
81 if (Destination is ImageResource Dest)
82 Dest.resource = this.resource?.CopyIfNotPreset(Destination.Document);
83 }
84
91 protected override async Task<SKImage> LoadImage(DrawingState State)
92 {
93 string ResourceName = await this.resource.Evaluate(State.Session, string.Empty);
94 if (!string.IsNullOrEmpty(ResourceName))
95 {
96 byte[] Bin = Resources.LoadResource(ResourceName);
97 SKBitmap Bitmap = SKBitmap.Decode(Bin);
98 return SKImage.FromBitmap(Bitmap);
99 }
100 else
101 return null;
102 }
103
108 public override void ExportStateAttributes(XmlWriter Output)
109 {
110 base.ExportStateAttributes(Output);
111
112 this.resource?.ExportState(Output);
113 }
114
115 }
116}
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:89
Abstract base class for images.
Definition: Image.cs:15
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.
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:13
static byte[] LoadResource(string ResourceName)
Loads a resource from an embedded resource.
Definition: Resources.cs:20
Base interface for all layout elements.
Layout2DDocument Document
Layout document.