-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPlatformIconLoader.cs
46 lines (40 loc) · 1.1 KB
/
PlatformIconLoader.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
using System.IO;
using Avalonia.Platform;
namespace Unilonia
{
internal class PlatformIconLoader : IPlatformIconLoader
{
public IWindowIconImpl LoadIcon(IBitmapImpl bitmap)
{
using (var stream = new MemoryStream())
{
bitmap.Save(stream);
return LoadIcon(stream);
}
}
public IWindowIconImpl LoadIcon(Stream stream)
{
return new FakeIcon(stream);
}
public IWindowIconImpl LoadIcon(string fileName)
{
using (var file = File.Open(fileName, FileMode.Open))
{
return new FakeIcon(file);
}
}
}
// Stores the icon created as a stream to support saving even though an icon is never shown
public class FakeIcon : IWindowIconImpl
{
private Stream stream = new MemoryStream();
public FakeIcon(Stream stream)
{
stream.CopyTo(this.stream);
}
public void Save(Stream outputStream)
{
stream.CopyTo(outputStream);
}
}
}