简体   繁体   English

如何设置 OpenTK window 图标

[英]how to set OpenTK window icon

I've tried looking around and I cant figure out how to set the top-left window Icon for an OpenTK gameWindow, I'm using C# and I'm trying to set the icon to a image file on my computer.我试过环顾四周,但我不知道如何为 OpenTK 游戏窗口设置左上角的 window 图标,我正在使用 C#,我正在尝试将图标设置为计算机上的图像文件。

My IDE is Visual Studio Code.我的 IDE 是 Visual Studio Code。

if you go to Project > (projectname) Properties > Application如果你 go 到 Project > (projectname) Properties > Application

you should see a section for setting your icon你应该看到一个设置你的图标的部分

脚步

if this section is blurred out如果这部分被模糊了

then open the.csproj file and add <ApplicationIcon>Path/to/file</ApplicationIcon>然后打开 .csproj 文件并添加<ApplicationIcon>Path/to/file</ApplicationIcon>

in the <PropertyGroup> section.<PropertyGroup>部分。

You can set the GameWindow icon by using the NativeWindowSettings.Icon property.您可以使用NativeWindowSettings.Icon属性设置GameWindow图标。

var nativeWindowSettings = NativeWindowSettings.Default;
nativeWindowSettings.Icon = new WindowIcon(width, height, data); // data is a byte[]

If you want a more concrete example, I'm using ImageSharp to actually load the image and create the WindowIcon :如果您想要一个更具体的示例,我正在使用ImageSharp实际加载图像并创建WindowIcon

public static WindowIcon CreateWindowIcon()
{
    var image = (Image<Rgba32>)Image.Load(Configuration.Default, "./Assets/Images/Logo.png");
    image.TryGetSinglePixelSpan(out var imageSpan);
    var imageBytes = MemoryMarshal.AsBytes(imageSpan).ToArray();
    var windowIcon = new WindowIcon(new OpenTK.Windowing.Common.Input.Image(image.Width, image.Height, imageBytes));

    return windowIcon;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM