GdkPixbuf如何用多个图片创建一个大图片

     今天遇到一个问题,就是背景图片要使用一个圆角矩形,而GUI没有提供现成的,只是提供了圆角矩形的两边和中间填充的图片,需要自己来建立这个图片(这样建立背景图片可以更灵活,一个GUI可以用在多个应用中,我想这是他们没有直接提供的原因)。

     具体来说,我要做到的事情是这样的,圆角矩形大小要为79*75,最左边圆角部分的图片给出,尺寸7*75,最右边圆角部分的图片也给出,尺寸5*75,中间部分要用一种1*75的图片连续帖这样填充出来,这样之后就得到我要的背景图片了。

     因为我不懂GDK_PIXBUF,请教了我们组的一个亲切的哥哥后,终于知道怎么做了,帖出来给大家分享下:

     思路如下:

     首先建立目标pixbuf:

                  GdkPixbuf *bg_pixbuf = gdk_pixbuf_new(GDK_CLORSPACE_RGB,TRUE,8,79,75);

(这个时候这个图片还是空的,我们之后会来填充)

     接着建立左边及右边圆角部分的那个pixbuf:

                  GdkPixbuf  *left_pixbuf   = gdk_pixbuf_new_from_file();

                  GdkPixbuf  *right_pixbuf = gdk_pixbuf_new_from_file();

      再建立中间填充部分那个1像素宽的pixbuf并将之拉伸到67像素宽:

                  GdkPixbuf  *center_pixbuf = gdk_pixbuf_new_from_file();

                  GdkPixbuf  *tianchong = gdk_pixbuf_scale_simple(center_pixbuf,67,75,GDK_INTERP_BILINEAR);

      此时,再将left_pixbuf, tianchong, right_pixbuf依次填充到bg_pixbuf就能得到我们要的目标图片了:

                  gdk_pixbuf_copy_area(left_pixbuf,0,0,7,75,bg_pixbuf,0,0);

                  gdk_pixbuf_copy_area(tianchong,0,0,67,75,bg_pixbuf,7,0);

                  gdk_pixbuf_copy_area(right_pixbuf,0,0,5,75,bg_pixbuf,74,0);

这样我们就可以使用bg_pixbuf了。

                       

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Table of Contents I. API Reference Initialization and Versions - Library version numbers. The GdkPixbuf Structure - Information that describes an image. Reference Counting and Memory Mangement - Functions for reference counting and memory management on pixbufs. File Loading - Loading a pixbuf from a file. File saving - Saving a pixbuf to a file. Image Data in Memory - Creating a pixbuf from image data that is already in memory. Inline data - Functions for inlined pixbuf handling. Scaling - Scaling pixbufs and scaling and compositing pixbufs Rendering - Rendering a pixbuf to a GDK drawable. Drawables to Pixbufs - Getting parts of a GDK drawable's image data into a pixbuf. Utilities - Utility and miscellaneous convenience functions. Animations - Animated images. GdkPixbufLoader - Application-driven progressive image loading. Module Interface - Extending gdk-pixbuf gdk-pixbuf Xlib initialization - Initializing the gdk-pixbuf Xlib library. Xlib Rendering - Rendering a pixbuf to an X drawable. X Drawables to Pixbufs - Getting parts of an X drawable's image data into a pixbuf. XlibRGB - Rendering RGB buffers to X drawables. II. Tools Reference gdk-pixbuf-csource - C code generation utility for GdkPixbuf images gdk-pixbuf-query-loaders - GdkPixbuf loader registration utility Index Index of deprecated symbols Index of new symbols in 2.2 Index of new symbols in 2.4 Index of new symbols in 2.6 Index of new symbols in 2.8 A. Porting applications from Imlib to gdk-pixbuf Introduction Differences between Imlib and gdk-pixbuf Initialization Memory management The Rendering Process Converting Applications to gdk-pixbuf Image loading and creation Rendering Images Scaling Images

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值