-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawStorage.cs
57 lines (52 loc) · 1.83 KB
/
DrawStorage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Xml.Serialization;
namespace SchetsEditor
{
[Serializable]
public class DrawStorage
{
public DrawStorage(List<DrawInstuction> undoList, List<DrawInstuction> redoList, Size afmeting, Bitmap backImage)
{
undo = undoList;
redo = redoList;
dimensions = afmeting;
backgroundImage = backImage;
}
public DrawStorage() { }
public List<DrawInstuction> undo { get; set; }
public List<DrawInstuction> redo { get; set; }
public Size dimensions { get; set; }
[XmlIgnore]
public Bitmap backgroundImage { get; set; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
[XmlElement("backgroundImage")]
public string backgroundImageSerialized
{
get
{ // serialize
if (backgroundImage == null) { return null; }
using (MemoryStream ms = new MemoryStream())
{
backgroundImage.Save(ms, ImageFormat.Bmp);
return Convert.ToBase64String(ms.ToArray());
}
}
set
{ // deserialize
if (value == null) { backgroundImage = null; }
else
{
byte[] bytes = Convert.FromBase64String(value);
MemoryStream mem = new MemoryStream(bytes);
backgroundImage = new Bitmap(mem);
}
}
}
public override string ToString() => $"Undo: {undo.ToString()}, Redo: {redo.ToString()}, meta: {(backgroundImage != null ? backgroundImage.ToString() : "".ToString())};";
}
}