// Copyright (c) The Avalonia Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. using System.IO; using Avalonia.Platform; namespace Avalonia.Native { // OSX doesn't have a concept of *window* icon. // Icons in the title bar are only shown if there is // an opened file (on disk) associated with the current window // see http://stackoverflow.com/a/7038671/2231814 class IconLoader : IPlatformIconLoader { class IconStub : IWindowIconImpl { private readonly IBitmapImpl _bitmap; public IconStub(IBitmapImpl bitmap) { _bitmap = bitmap; } public void Save(Stream outputStream) { _bitmap.Save(outputStream); } } public IWindowIconImpl LoadIcon(string fileName) { return new IconStub( AvaloniaLocator.Current.GetService().LoadBitmap(fileName)); } public IWindowIconImpl LoadIcon(Stream stream) { return new IconStub( AvaloniaLocator.Current.GetService().LoadBitmap(stream)); } public IWindowIconImpl LoadIcon(IBitmapImpl bitmap) { var ms = new MemoryStream(); bitmap.Save(ms); ms.Seek(0, SeekOrigin.Begin); return LoadIcon(ms); } } }