Re: Copy parts of one image to another

Tim Evans wrote:

Trevor Fancher wrote:

This is driving me absolutely nuts.  I have been trying for the past 3
days.  I have searched on Google and everywhere else logical.  My
question is, "How do I copy part of one image to part of another?"

What I want to do is copy a 16x16 area from my tileset image to a
background image and then display the results in a GtkEventbox.  I am
so frustrated because I just cannot figure this out.  If someone could
give me some example code doing this task, I would be *very*

Load your tileset image using:
  GdkPixbuf *tileset;
  GError *error=NULL;
  tileset = gdk_pixbuf_new_from_file ("tileset.png", &error);

Create an empty 16x16 tile pixbuf using:
  GdkPixbuf *tile;
  tile = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 16, 16);

Oops, I left out a step here:

  Copy tile <i,j> into the tile pixbuf:
    gint i, j;
    gdk_pixbuf_copy_area (tileset, i*16, j*16, 16, 16, tile, 0, 0);

Then display each tile in a GtkImage widget:
  GtkWidget *image;
  image = gtk_image_new ();
  gtk_image_set_from_pixbuf (GTK_IMAGE (image), tile);

And place the image inside the eventbox:
  gtk_container_add (GTK_CONTAINER (eventbox), image);

Tim Evans
Applied Research Associates NZ

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