Re: Render Text to Pixbuf
- From: John Spray <jcspray icculus org>
- To: Paul Davis <pjdavis engineering uiowa edu>
- Cc: gtkmm-list <gtkmm-list gnome org>
- Subject: Re: Render Text to Pixbuf
- Date: Mon, 30 Apr 2007 20:50:55 +0100
On Mon, 2007-04-30 at 14:32 -0500, Paul Davis wrote:
> Hey,
>
> I'm working on trying to render text to a image that eventually gets
> painted on screen. Basically all I have access to is a Gdk::Pixbuf
> which I edit directly when I'm trying to do the text rendering.
Here's some code that I wrote quickly a while ago, no guarantees as to
how good/right it is. GTK+ I'm afraid, but you should have no trouble
translating to gtkmm.
John
GdkPixbuf *DrawOverlay (GdkPixbuf *pb, int w, int h, gchar *text)
{
GdkPixmap *pm = gdk_pixmap_new (NULL, w, h, 24);
GdkGC *gc = gdk_gc_new (pm);
gdk_draw_pixbuf (pm, gc, pb,
0, 0, 0, 0,
w, h,
GDK_RGB_DITHER_NONE,
0,
0);
GtkWidget *scratch = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_realize (scratch);
PangoLayout *layout = gtk_widget_create_pango_layout (scratch, NULL);
gtk_widget_destroy (scratch);
gchar *markup = g_strdup_printf (
"<big><b><span foreground='#FFFF00'>%s</span></b></big>", text);
pango_layout_set_markup (layout, markup, -1);
g_free (markup);
gdk_draw_layout (pm, gc, 10, 10, layout);
g_object_unref (layout);
GdkPixbuf *ret = gdk_pixbuf_get_from_drawable
(NULL,
pm,
NULL,
0,
0,
0,
0,
w,
h);
return ret;
}
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]