Re: [gtk-list] Inline images





On Sat, 28 Jun 1997, Arun Sharma wrote:

> Hi,
> 
> Can anybody help me understand what needs to be done to display inline
> images using Gtk ? Can the respective plug-ins be modified in some way
> to fit the purpose ?

You could do it with Gimp plug-ins, but I don't think that's the best 
way. The Gimp plug-in interface is somewhat complex, and involves tiles 
and shared memory.

The best widget for inline image display is gtk_preview. There are other
options, but this one takes care of dithering to display on 8-bit displays
and other such details. It has a pretty clean interface for grayscale and
RGB images, but you'd still need to take care of decoding other files
formats. There are a few options here. You can use a package like pbmplus
or ImageMagick, or you can use the image modules from Gzilla. 

If you choose to go the latter route, you'll need gzillabytesink,
gzillaimgsink, gzillagif, gzillajpeg, and gzillaimage. If you use
gzillajpeg, you'll also need libjpeg. The code sequence looks something
like this: 

GtkWidget *widget;
GzillaImgSink *imgsink;
GzillaByteSink *bytesink;

imgsink = gzilla_image_new (width, height, "", bg_color);
/* width and height can be 0 if you don't want the image resized.
   bg_color is in 0xrrggbb format - gtk gray is 0xd6d6d6. */
widget = gzilla_image_widget (imgsink);
bytesink = gzilla_gif_new (imgsink);
gzilla_bytesink_write (bytesink, gif_buf, gif_buf_size);
gzilla_bytesink_close (bytesink);
gzilla_bytesink_destroy (bytesink);

Then, you pack the widget the same way you'd pack any GTK widget. If 
images could be large, I'd recommend splitting the bytesink_write calls 
into 8k chunks, fed by an idle process. Otherwise, the whole UI will be 
unresponsive while the image decodes.

You can't embed widgets into a gtk_text, but if you switch to Gzilla's
gtk_page, it would be no problem. gtk_page has no dependencies, but the
interface will change slightly (it will become gzilla_page, and will get
packed into a gtk_gzilla_scroller rather than a gtk_scrolled window). The 
interface is a bit different than gtk_text - you have to split the text 
into lines and paragraphs yourself. If you want word wrapping, you also 
have to split into words. I can give code examples if you like.

Raph



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]