图像

../../../_images/image.png

GtkPicture 旨在与使用其自然大小的图像一起使用;对于固定大小的图像,如图标,您应该改用 GtkImage

// create an image and set the content of the image using the gnome-image.png file
GtkWidget *image = gtk_picture_new_for_filename ("gnome-image.png");

重要提示

如果图像文件未成功加载,图像将包含一个“损坏图像”图标。为此代码工作,gnome-image.png 文件需要位于当前目录中。

Picture 小部件的有用方法

  • set_keep_aspect_ratio(True) 将调整 GtkPicture 小部件的大小,以便在调整小部件大小时保持图像的纵横比。

  • set_alternative_text("An image of a 1000 words") 将字符串“An image of a 1000 words”设置为图像的文本表示;此文本将由辅助功能工具使用。

API 参考