class GdkPixbuf::PixbufLoader
- GdkPixbuf::PixbufLoader
- GObject::Object
- Reference
- Object
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:
- [signal@Gdk::Pixbuf.PixbufLoader::size-prepared] will be emitted as
soon as the image has enough information to determine the size of
the image to be used. If you want to scale the image while loading
it, you can call
Gdk::Pixbuf::PixbufLoader#size=
in response to this signal. - [signal@Gdk::Pixbuf.PixbufLoader::area-prepared] will be emitted as
soon as the pixbuf of the desired has been allocated. You can obtain
the
Gdk::Pixbuf
instance by callingGdk::Pixbuf::PixbufLoader#pixbuf
. If you want to use it, simply acquire a reference to it. You can also callgdk_pixbuf_loader_get_pixbuf()
later to get the same pixbuf. - [signal@Gdk::Pixbuf.PixbufLoader::area-updated] will be emitted every time a region is updated. This way you can update a partially completed image. Note that you do not know anything about the completeness of an image from the updated area. For example, in an interlaced image you will need to make several passes before the image is done loading.
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.crConstructors
-
.new : self
Creates a new pixbuf loader object.
-
.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.
-
.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.
Class Method Summary
-
.g_type : UInt64
Returns the type id (GType) registered in GLib type system.
Instance Method Summary
-
#animation : GdkPixbuf::PixbufAnimation?
Queries the #Gdk::PixbufAnimation that a pixbuf loader is currently creating.
- #area_prepared_signal
- #area_updated_signal
-
#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.
- #closed_signal
-
#format : GdkPixbuf::PixbufFormat?
Obtains the available information about the format of the currently loading image file.
-
#pixbuf : GdkPixbuf::Pixbuf?
Queries the #Gdk::Pixbuf that a pixbuf loader is currently creating.
-
#set_size(width : Int32, height : Int32) : Nil
Causes the image to be scaled while it is loaded.
- #size_prepared_signal
-
#write(buf : Enumerable(UInt8)) : Bool
Parses the next
count
bytes in the given image buffer. - #write(*buf : UInt8)
-
#write_bytes(buffer : GLib::Bytes) : Bool
Parses the next contents of the given image buffer.
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
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().
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
Instance Method Detail
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
.
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.
Obtains the available information about the format of the currently loading image file.
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()).
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.