Thread: How do I use images in a c program

  1. #1
    Registered User errigour's Avatar
    Join Date
    Mar 2009
    Posts
    102

    How do I use images in a c program

    I want to use images in a c program I use the operating system linux since windows really doesn't support programming with free compilers. O kind of want to make a grid maybea home made map maker but I have to know how to use images and place them in a grid.

  2. #2
    Codus Conjectus spongefreddie's Avatar
    Join Date
    Sep 2010
    Location
    USA
    Posts
    86
    I'm no expert, but I'm pretty sure GCC, Pelles C, Open Watcom, Borland C++ 5.5 are all free, cross platform (including Windows), high-quality C compilers.

    Also, Code:Blocks runs on Linux, Windows *and* Apple OS's.
    V8 Interceptor: KDE 5.25.5 on Manjaro Linux 22.0.0 "Sikaris"
    Steering wheel: gcc 12.2.0 in Kate
    Supercharger: NASM 2.15.05
    Engine: AMD Ryzen 7 1700
    Dashboard: NVIDIA GeForce GTX 1060 6GB
    Rusty old trailer for hauling 3% of my Steam catalog: Windows 7 Pro 64bit SP1
    3 Antique Ford Model T automobiles for vintage LAN gaming: Windows XP SP3
    Sturdy buckboard for DOS LAN gaming: DOSBox 0.74-3 on Windows XP SP3

  3. #3
    Registered User hellork's Avatar
    Join Date
    Nov 2010
    Posts
    39
    Since you said you use Linux, look at GTK+ - About
    It is cross-platform and supports loading images into a click-able map.

    Some boilerplate code from GtkImage:
    Code:
    static gboolean
    button_press_callback (GtkWidget      *event_box,
                           GdkEventButton *event,
                           gpointer        data)
    {
      g_print ("Event box clicked at coordinates %f,%f\n",
               event->x, event->y);
    
      /* Returning TRUE means we handled the event, so the signal
       * emission should be stopped (don't call any further
       * callbacks that may be connected). Return FALSE
       * to continue invoking callbacks.
       */
      return TRUE;
    }
    
    static GtkWidget*
    create_image (void)
    {
      GtkWidget *image;
      GtkWidget *event_box;
    
      image = gtk_image_new_from_file ("myfile.png");
    
      event_box = gtk_event_box_new ();
    
      gtk_container_add (GTK_CONTAINER (event_box), image);
    
      g_signal_connect (G_OBJECT (event_box),
                        "button_press_event",
                        G_CALLBACK (button_press_callback),
                        image);
    
      return image;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. redirection program help needed??
    By Unregistered in forum Linux Programming
    Replies: 0
    Last Post: 04-17-2002, 05:50 AM