Thread: Drawing an image in C

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    35

    Drawing an image in C

    I have drawn a Diamond/rhombus in C, but I don't now how i can fill the shape in, any ideas?
    Code:
        #include <stdio.h>
        #include <gd.h>
         
        int main()
        {
          /* Declare and initialise variables for a new image.
             These steps are done once before using drawing functions. */
          gdImagePtr gdImage = gdImageCreate( 300, 300 );
          FILE *jpgFile = NULL;
          int red;
         
          /* The first call to gdImageColorAllocate() always sets the image background.
             This step can only be done once before using drawing functions. */
          gdImageColorAllocate( gdImage, 250, 250, 250 );
         
          /* Subsequent calls to gdImageColorAllocate() creates new colors for drawing.
             It is similar using a paint brush with a specific color. The brush can be
             used over and over. This is only needed each time a new color is required. */
          red = gdImageColorAllocate( gdImage, 255, 0, 0 );
         
          /* Most of the work is done by using drawing functions.
             These functions set the line width to 4 and draws a diagonal line. */
          gdImageSetThickness( gdImage, 2 );
          gdImageLine( gdImage, 150, 0, 0, 150, red );
          gdImageSetThickness( gdImage, 2 );
          gdImageLine( gdImage, 150, 0, 300, 150, red );
          gdImageSetThickness( gdImage, 2 );
          gdImageLine( gdImage, 150, 300, 0, 150, red );
          gdImageSetThickness( gdImage, 2 );
          gdImageLine( gdImage, 300, 150, 150, 300, red );
         
         
          /* These steps save the image in memory out to a physical file on the server.
             These steps are done once when the drawing is done. */
          jpgFile = fopen( "test.jpg", "wb" );
          gdImageJpeg( gdImage, jpgFile, -1 );
         
          /* These steps clear all memory and files used with the image.
             These steps are done once when the image is no longer used. */
          fclose( jpgFile );
          gdImageDestroy( gdImage );
        }

  2. #2
    Registered User
    Join Date
    Jan 2013
    Posts
    35
    Drawing an image in C-autogcccwpshp-jpg

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    It looks like you're using this library. Perhaps one of the functions listed on that page might fill the bill?

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    google 'how to flood fill'. there are several algorithms for doing that.
    Flood Fill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 07-16-2010, 10:35 AM
  2. Replies: 4
    Last Post: 03-13-2010, 05:10 AM
  3. Replies: 13
    Last Post: 11-20-2009, 04:43 PM
  4. Drawing on image (Multithreading)
    By Devils Child in forum C# Programming
    Replies: 6
    Last Post: 07-26-2009, 10:52 AM
  5. Problems with Image Magick [Unable to Quantisize Image]
    By Maragato in forum C Programming
    Replies: 1
    Last Post: 09-18-2006, 10:41 PM