Ruby/GTK应用笔记(2): Gdk::Pixbuf

Gdk::Pixbuf是GTK库极为重要的一个组件,从图标到图像控件,到处都可以看到它的身影,Gdk::Pixbuf让GTK使用图像资源变得轻松许多。

Gdk::Pixbuf的用法文档说的比较清楚了,就不再重复,值得注意的是,Pixbuf在内部如何存储图像文档并未详细说明,这会给使用带来一些麻烦。

1). Pixbuf#pixels: 返回的是内部像素内存的一份[b]拷贝[/b],而不是引用。因此无法通过改变pixels buf而改变图像内容。这似乎很不方便,不过这种设计使得Pixbuf管理像素内存比较简单。

2). Pixbuf#pixels= :上面说过pixbuf返回的是拷贝,使得Pixbuf管理内部像素内存简单化,因此‘pixels=’这个方法实际上是不存在的(要不然就破坏了Pixbuf管理内部像素的简单性),RubyGnome网站上的文档是错误的。至少到目前为止(0.17.0-rc1),Pixbuf#pixels=方法是不存在的。

要想修改图像怎么办?可以这样:
buf = Pixbuf#pixels
buf[x] = y
new_pixbuf = Pixbuf#new(buf, colorspace, has_alpha, width, height, bps, rowstride)


3). Pixbuf#new(src, src_x, src_y, width, height): 从一个现存的Pixbuf生成新的Pixbuf对象时,两个Pixbuf共享同一个像素内存。特别的,当新的Pixbuf是旧Pixbuf的一个子区域时,尽管width已经是变小了,但是rowstride却是和原来的一样,因此要特别小心。

4). Pixbuf#pixels: 前面说过,pixels返回内部像素内存的一份拷贝,但是pixels.size到底是多大呢? 等于height * rowstride么?不然。当width不是4的整数倍是,pixbuf[i]有可能[/i]在32bit系统中为了优化而把rowstride凑到4的整数,但是最后一行却没有必要进行优化,因此会发现pixels.size < height * rowstride。(这里说'有可能'是因为这种优化只会发生在从文件加载而产生的新Pixbuf对象,对于从已有的像素内存产生Pixbuf对象则不会发生)。

研究Pixbuf对像素内存的管理,主要是为了在Pixbuf和其它对象互相转换时不会发生错误,例如可以从Pixbuf对象生成Camellia对象(Camellia是一个计算机图像处理库),或反之。对于一般的GTK程序,则不需要太关心pixels的格式。
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、付费专栏及课程。

余额充值