Re: embedding bitmap images into code



Le 06/10/2010 09:44, Igor Gorbounov a écrit :
06.10.2010 11:29, Guillaume Brocker пишет:
Hello !

XPM images [1] may be a solution. In this format, an image is stored
as a char array defined in a C header file. You will just need to
include that file to get the image embedded in your code.

The problem is that cairo does not provide a way to handle XPM data.
You can use Gdk::Pixbuf [2] to load XPM data and then
Gdk::Cairo::set_source_pixbuf [3].

Thanks for your answer!
It looks like I've solved this problem at last:

I've taken a C-structure with data, made by Gimp (save as C-code), it
looks like this:

/* GIMP RGBA C-Source image dump (stock_form-time-field.c) */

static const struct {
guint width;
guint height;
guint bytes_per_pixel; /* 3:RGB, 4:RGBA */
guint8 pixel_data[24 * 24 * 4 + 1];
} gimp_image = {
24, 24, 4,
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\23\0\0\0o"
...
This was made from a PNG picture (24x24 pixels). Then I've placed
this image in my drawingarea this way:

int stride =
Cairo::ImageSurface::format_stride_for_width(Cairo::FORMAT_ARGB32,
gimp_image.width);
Cairo::RefPtr<Cairo::ImageSurface> test_image =
Cairo::ImageSurface::create((uint8_t *)&gimp_image.pixel_data,
Cairo::FORMAT_ARGB32, gimp_image.width, gimp_image.height, stride);
context->set_source(test_image, 50, 50);
context->paint();

This is very interesting. I didn't know the GIMP C-code format.

Guillaume


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