This blog is under construction

Wednesday 11 September 2013

imagesize example in c

Header file:
    graphics.h

Synopsis:
      unsigned far imagesize(int left, int top, int right, int bottom);
     (left, top) - top left of the specified rectangular area
     (right, bottom) - bottom right of the specified rectangular area
     
Description:
     imagesize() returns the number of bytes required to store the specified bit image.


imagesize function in c graphics



  #include <graphics.h>
  #include <stdlib.h>
  #include <stdio.h>
  #include <conio.h>
  #include <alloc.h>
  #include <dos.h>


  int main(void) {
        /* request auto detection */
        int gdriver=DETECT, gmode, err, color;
        int i, x[2], y[2], midx, midy, radius = 60;
        void far *image;
        char str[256];
        unsigned long size;

        /* initialize graphic driver */
        initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");
        err = graphresult();

        if (err != grOk) {
                /* error occurred */
                printf("Graphics error: %s\n",
                                grapherrormsg(err));
                getch();
                return 0;
        }

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

        /* concentric circle  */
        for (i = 1; i <= 5; i++) {
                if (i % 2 == 0) {
                        color = 15;
                } else {
                        color = i;
                }

                setcolor(color);
                setfillstyle(SOLID_FILL, color);
                circle(midx, midy, radius);
                floodfill(midx, midy, color);
                radius = radius - 10;
        }

        /* top left and bottom right for image 1 */
        x[0]= midx, y[0] = midy;
        x[1]= midx + 60, y[1] = midy + 60;


        size = imagesize(x[0], y[0], x[1], y[1]);
        image = farmalloc(size);

        if (!image) {
                printf("Error: unable to allocate requested block");
                getch();
                closegraph();
                exit(1);
        }

        /* copies image from screen to memory */
        getimage(x[0], y[0], x[1], y[1], image);

        /* prints image from memory to screen */
        putimage(0, 0, image, COPY_PUT);


        /* prints the size of the copied image (in bytes) */

        sprintf(str, "Size of the copied image is %d", size);
        outtextxy(20, 90, str);

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





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


No comments:

Post a Comment