This blog is under construction

Saturday 14 September 2013

getpixel example in c

Header file:
    graphics.h

Synopsis:
      int getpixel (int x, int y);
     
Description:
     getpixel() gets the color of the pixel located at (x, y).


getpixel function in c graphics



  #include <stdio.h>
  #include <conio.h>
  #include <graphics.h>

  int main() {
        /* request auto detection */
        int graphicDriver = DETECT;
        int graphicMode, err, midx, midy;
        char msg[32];

        /* initialize graphic driver and mode */
        initgraph(&graphicDriver, &graphicMode,
                                        "C:/TURBOC3/BGI");
        err = graphresult();

        if (err != grOk) {
                /* error occurred */
                printf("Graphic Error: %s",
                                grapherrormsg(err));
                return 0;
        }

        /* mid position at x and y-axis */
        midx = getmaxx() / 2;
        midy = getmaxy() / 2;

        /* draws a circle using the current draw color */
        setcolor(10);
        setfillstyle(SOLID_FILL, 10);
        circle(midx, midy, 100);
        floodfill(midx, midy, 10);

        /* store the color and position of the pixel in a string */
        sprintf(msg, "color of the pixel at (%d, %d) is %d",
                                midx, midy, getpixel(midx, midy));

        /* print the text at (50, 50) */
        outtextxy(50, 50, msg);

        /* clean graph */
        getch();
        closegraph();
        return 0;
  }





Output: (getpixel built-in function in c graphics.h)


No comments:

Post a Comment