GTKmm:对文件中的图像进行编码
GTKmm : Encode image in the file?
我有一个使用显示图像的UI
add(*manage(new Gtk::Image("image.png")));
但该应用程序在每次lauch时都会从硬盘中提取它,如果它不在那里,它就会坏掉,等等。我如何对image.png进行编码,以便在代码中发送它?
GResource对此非常有用。它允许您在*.gressource.xml文件中列出资源文件(如图像)。glib编译资源实用程序然后从中生成一个.c文件,然后将该.c文件链接到应用程序中。你需要对Makefile.am进行一些更改才能正常实现,但你可以查看一些现有的项目,比如我的Glom项目:
https://git.gnome.org/browse/glom/tree/Makefile_glom.am?id=f79223fa7ebbb0cfc12c6a47366136de478d57cb#n44
然后可以使用API,如Gtk::Image::set_from_resource()。或者,您可以使用API直接获取数据,如g_resources_open_stream(),甚至可以使用g_resources_enumerate_childrem()迭代所有可用的资源。
以下是我的Glom项目中的一些相关承诺:
https://git.gnome.org/browse/glom/commit/?id=f79223fa7ebbb0cfc12c6a47366136de478d57cb
https://git.gnome.org/browse/glom/commit/?id=9cd1b6dab94191abbb9392304e867bddb2bba766
将"image.png"转换为XPM文件;FWIW,标准XPM格式是可编译的C代码。但更重要的是,还有pixbuf和pixmap函数可以直接加载XPM数据。
对于Linux中的gtkmm,您可以将所有资源文件(css、glade、images)转换为一个glib-compile-resources
文件。然后将创建一个c文件。因此,无需单独导出资源文件。
为了首先完成所有这些操作,您需要创建*.gresource.xml
文件。
我需要将png图像转换为pixbuf格式,由于某些原因png对我不起作用。(你也可以尝试使用png格式)
例如:
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/myproject">
<file preprocess="xml-stripblanks" alias="tiltdisplay.glade">Resources/tiltdisplay.glade</file>
<file alias="styles.css">Resources/styles.css</file>
<!-- png image is converted to pixbuf image using command >
< gdk-pixbuf-pixdata -r white_argos.png white_argos.pixbuf-->
<file alias="white_argos.pixbuf">Resources/white_argos.pixbuf</file>
</gresource>
</gresources>
创建此xml文件后,可以使用以下命令生成glib-compile-resources
。
glib-compile-resources --target=path/to/resources.c --generate-source /path/to/my.gresource.xml
完成此操作后,将此resources.c
添加到代码中。为了从c++代码中访问一个项目,请执行以下操作。
img->set_from_resource("/myproject/white_argos.pixbuf"); // gresource prefix + alias
// or
cssProvider->load_from_resource("/myproject/styles.css");
// or
Gtk::Builder::create_from_resource("/myproject/tiltdisplay.glade")
- Base64 图像编码不正确
- 当通过tcp接收编码图像的消息时,zmq在第二个循环中崩溃
- 如何将 MATLAB 图像处理库内置函数转换为 MATLAB 编码器代码生成不支持的 C++?
- 如何将硬编码图像加载到 OpenGL 纹理中
- 将原始视频图像转换为VPX编码器的I420
- 将 JPG 编码数组从 ROS sensor_msgs/压缩图像保存到 roscpp 中的文件
- BASE64图像文件用C 编码
- FFMPEG H264对每个图像进行编码
- OpenCV 如何为imencode编码原始图像信息
- 如何使用Imebra库将压缩像素(用我自己的编码器压缩)回到DICOM图像文件中
- 在FLTK中显示Base64编码图像
- 同一图像的不同 base64 编码
- JPEG编码位图(BMP)图像从文件使用libjpeg / C++
- Windows媒体基础使用原始图像对视频进行编码
- 用Qt解码用Java ImageIO类编码的图像
- C++图像编码/解码库
- 如何根据C++程序中生成的多个图像对视频进行编码,而不将单独的帧图像写入磁盘
- 用c++将数组编码为jpeg图像
- GTKmm:对文件中的图像进行编码
- WebM编码器示例-如何将一系列图像编码为WebM视频