Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ImageFile.cs
1using SkiaSharp;
2using System.IO;
3using System.Threading.Tasks;
4using System.Xml;
7
9{
13 public class ImageFile : Image
14 {
15 private StringAttribute fileName;
16
22 public ImageFile(Layout2DDocument Document, ILayoutElement Parent)
23 : base(Document, Parent)
24 {
25 }
26
30 public override string LocalName => "ImageFile";
31
36 {
37 get => this.fileName;
38 set => this.fileName = value;
39 }
40
45 public override Task FromXml(XmlElement Input)
46 {
47 this.fileName = new StringAttribute(Input, "fileName", this.Document);
48
49 return base.FromXml(Input);
50 }
51
56 public override void ExportAttributes(XmlWriter Output)
57 {
58 base.ExportAttributes(Output);
59
60 this.fileName?.Export(Output);
61 }
62
69 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
70 {
71 return new ImageFile(Document, Parent);
72 }
73
78 public override void CopyContents(ILayoutElement Destination)
79 {
80 base.CopyContents(Destination);
81
82 if (Destination is ImageFile Dest)
83 Dest.fileName = this.fileName?.CopyIfNotPreset(Destination.Document);
84 }
85
92 protected override async Task<SKImage> LoadImage(DrawingState State)
93 {
94 string FileName = await this.fileName.Evaluate(State.Session, string.Empty);
95 if (!string.IsNullOrEmpty(FileName) && File.Exists(FileName))
96 {
97 byte[] Bin = await Files.ReadAllBytesAsync(FileName);
98 SKBitmap Bitmap = SKBitmap.Decode(Bin);
99 return SKImage.FromBitmap(Bitmap);
100 }
101 else
102 return null;
103 }
104
109 public override void ExportStateAttributes(XmlWriter Output)
110 {
111 base.ExportStateAttributes(Output);
112
113 this.fileName?.ExportState(Output);
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
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
Definition: ImageFile.cs:78
StringAttribute FileNameAttribute
Filename
Definition: ImageFile.cs:36
override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
Creates a new instance of the layout element.
Definition: ImageFile.cs:69
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
Definition: ImageFile.cs:45
ImageFile(Layout2DDocument Document, ILayoutElement Parent)
An image defined in a file.
Definition: ImageFile.cs:22
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
Definition: ImageFile.cs:109
override string LocalName
Local name of type of element.
Definition: ImageFile.cs:30
override async Task< SKImage > LoadImage(DrawingState State)
Loads the image defined by the element.
Definition: ImageFile.cs:92
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
Definition: ImageFile.cs:56
Abstract base class for images.
Definition: Image.cs:15
Layout2DDocument Document
Layout document.
Contains static methods
Definition: Files.cs:14
static async Task< byte[]> ReadAllBytesAsync(string FileName)
Reads a binary file asynchronously.
Definition: Files.cs:20
Base interface for all layout elements.
Layout2DDocument Document
Layout document.