class GdkPixbuf::PixbufLoader

Overview

Incremental image loader.

Gdk::PixbufLoader provides a way for applications to drive the process of loading an image, by letting them send the image data directly to the loader instead of having the loader read the data from a file. Applications can use this functionality instead of gdk_pixbuf_new_from_file() or gdk_pixbuf_animation_new_from_file() when they need to parse image data in small chunks. For example, it should be used when reading an image from a (potentially) slow network connection, or when loading an extremely large file.

To use Gdk::PixbufLoader to load an image, create a new instance, and call Gdk::Pixbuf::PixbufLoader#write to send the data to it. When done, Gdk::Pixbuf::PixbufLoader#close should be called to end the stream and finalize everything.

The loader will emit three important signals throughout the process:

Loading an animation

Loading an animation is almost as easy as loading an image. Once the first [signal@Gdk::Pixbuf.PixbufLoader::area-prepared] signal has been emitted, you can call Gdk::Pixbuf::PixbufLoader#animation to get the Gdk::Pixbuf::PixbufAnimation instance, and then call and Gdk::Pixbuf::PixbufAnimation#iter to get a Gdk::Pixbuf::PixbufAnimationIter to retrieve the pixbuf for the desired time stamp.

Defined in:

lib/gi-crystal/src/auto/gdk_pixbuf-2.0/pixbuf_loader.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class GObject::Object

bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void)? data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void)? qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void)?) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void)? steal_data, steal_qdata(quark : UInt32) : Pointer(Void)? steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, cast?(obj : GObject::Object) : self? cast?, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

compat_control(what : UInt64, data : Pointer(Void)?) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Constructor Detail

def self.new : self #

Creates a new pixbuf loader object.


def self.new_with_mime_type(mime_type : String) : self #

Creates a new pixbuf loader object that always attempts to parse image data as if it were an image of MIME type @mime_type, instead of identifying the type automatically.

This function is useful if you want an error if the image isn't the expected MIME type; for loading image formats that can't be reliably identified by looking at the data; or if the user manually forces a specific MIME type.

The list of supported mime types depends on what image loaders are installed, but typically "image/png", "image/jpeg", "image/gif", "image/tiff" and "image/x-xpixmap" are among the supported mime types. To obtain the full list of supported mime types, call gdk_pixbuf_format_get_mime_types() on each of the #Gdk::PixbufFormat structs returned by gdk_pixbuf_get_formats().


def self.new_with_type(image_type : String) : self #

Creates a new pixbuf loader object that always attempts to parse image data as if it were an image of type @image_type, instead of identifying the type automatically.

This function is useful if you want an error if the image isn't the expected type; for loading image formats that can't be reliably identified by looking at the data; or if the user manually forces a specific type.

The list of supported image formats depends on what image loaders are installed, but typically "png", "jpeg", "gif", "tiff" and "xpm" are among the supported formats. To obtain the full list of supported image formats, call gdk_pixbuf_format_get_name() on each of the #Gdk::PixbufFormat structs returned by gdk_pixbuf_get_formats().


Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


Instance Method Detail

def animation : GdkPixbuf::PixbufAnimation? #

Queries the #Gdk::PixbufAnimation that a pixbuf loader is currently creating.

In general it only makes sense to call this function after the [signal@Gdk::Pixbuf.PixbufLoader::area-prepared] signal has been emitted by the loader.

If the loader doesn't have enough bytes yet, and hasn't emitted the area-prepared signal, this function will return NULL.


def area_prepared_signal #

def area_updated_signal #

def close : Bool #

Informs a pixbuf loader that no further writes with gdk_pixbuf_loader_write() will occur, so that it can free its internal loading structures.

This function also tries to parse any data that hasn't yet been parsed; if the remaining data is partial or corrupt, an error will be returned.

If FALSE is returned, error will be set to an error from the GDK_PIXBUF_ERROR or G_FILE_ERROR domains.

If you're just cancelling a load rather than expecting it to be finished, passing NULL for error to ignore it is reasonable.

Remember that this function does not release a reference on the loader, so you will need to explicitly release any reference you hold.


def closed_signal #

def format : GdkPixbuf::PixbufFormat? #

Obtains the available information about the format of the currently loading image file.


def pixbuf : GdkPixbuf::Pixbuf? #

Queries the #Gdk::Pixbuf that a pixbuf loader is currently creating.

In general it only makes sense to call this function after the [signal@Gdk::Pixbuf.PixbufLoader::area-prepared] signal has been emitted by the loader; this means that enough data has been read to know the size of the image that will be allocated.

If the loader has not received enough data via gdk_pixbuf_loader_write(), then this function returns NULL.

The returned pixbuf will be the same in all future calls to the loader, so if you want to keep using it, you should acquire a reference to it.

Additionally, if the loader is an animation, it will return the "static image" of the animation (see gdk_pixbuf_animation_get_static_image()).


def set_size(width : Int32, height : Int32) : Nil #

Causes the image to be scaled while it is loaded.

The desired image size can be determined relative to the original size of the image by calling gdk_pixbuf_loader_set_size() from a signal handler for the ::size-prepared signal.

Attempts to set the desired image size are ignored after the emission of the ::size-prepared signal.


def size_prepared_signal #

def write(buf : Enumerable(UInt8)) : Bool #

Parses the next count bytes in the given image buffer.


def write(*buf : UInt8) #

def write_bytes(buffer : GLib::Bytes) : Bool #

Parses the next contents of the given image buffer.