如何使用GTK +作为GUI将图像文件作为图标编译为EXE? [英] How to compile an image file as icon into an EXE using GTK+ as GUI?

查看:127
本文介绍了如何使用GTK +作为GUI将图像文件作为图标编译为EXE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何将图像设置为GtkWindow的图标.

I know how to set up an image as the icon of a GtkWindow.

GtkWindow * window;
gtk_window_set_icon_from_file(window, "icon.png", NULL);

并与exe一起放置icon.png.

and place icon.png together with the exe.

但是如果我不想将该图像文件保存在文件夹中怎么办?我希望它以某种方式捆绑在exe文件中.

But what if I don't want to keep that image file in my folder? I want it somehow bundled inside the exe file.

我知道这可以在Qt中使用qrc来完成.我也可以在GTK +中这样做吗?

I know this can be done with qrc in Qt. Can I do this in GTK+ too?

推荐答案

我现在知道该怎么做.

首先,我必须将该图像转换为纯代码.

First, I have to convert that image into plain code.

说我想将icon.png作为图标.

运行此命令将其转换为名为icon_1的变量.如果没有二进制文件,请抓住它.

Run this command to convert it as an variable named icon_1. Grab that binary if you don't have it.

gdk-pixbuf-csource --raw --name=icon_1 icon.png

它将显示在命令提示符下.但我想您想将其保存到文件中.所以

It will show on the command prompt. But I suppose you want to save it to a file. So

gdk-pixbuf-csource --raw --name=icon_1 icon.png>icon.c

将在Windows中完成这项工作.

will do the job in Windows.

现在可以使用变量icon_1.

下一步.调用gdk_pixbuf_new_from_inline()icon_1创建新的GdkPixbuf *.

Next step. Call gdk_pixbuf_new_from_inline() to create a new GdkPixbuf * from icon_1.

GdkPixbuf * icon_title = gdk_pixbuf_new_from_inline(-1, icon_1, false, NULL);

您现在可以使用新创建的icon_title调用gtk_window_set_icon()来设置窗口的图标.

You can now call gtk_window_set_icon() with that newly created icon_title to set up the icon of the window.

gtk_window_set_icon(window, icon_title);

还请记住,如果将icon_1保留在独立的C文件中,则必须包含glib.h以便可以对其进行编译,因为它使用的类型为guint8,并且在使用前将其替换为外部变量,以便可以链接.

Also remember that if you keep icon_1 in a standalone C file, you have to include glib.h so that it can be compiled because it uses type guint8, and extern that variable before using so that it can be linked.

更多详细信息:

https://developer.gnome.org/gdk-pixbuf/unstable/gdk-pixbuf-Image-Data-in-Memory.html#gdk-pixbuf-new-from-inline

这篇关于如何使用GTK +作为GUI将图像文件作为图标编译为EXE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆