csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
50 lines
1.5 KiB
// 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<IPlatformRenderInterface>().LoadBitmap(fileName));
|
|
}
|
|
|
|
public IWindowIconImpl LoadIcon(Stream stream)
|
|
{
|
|
return new IconStub(
|
|
AvaloniaLocator.Current.GetService<IPlatformRenderInterface>().LoadBitmap(stream));
|
|
}
|
|
|
|
public IWindowIconImpl LoadIcon(IBitmapImpl bitmap)
|
|
{
|
|
var ms = new MemoryStream();
|
|
bitmap.Save(ms);
|
|
ms.Seek(0, SeekOrigin.Begin);
|
|
return LoadIcon(ms);
|
|
}
|
|
}
|
|
}
|
|
|