Putimage() Function

putimage() function is used to display the image on the screen previously captured by the getimage() function.

Declaration

void putimage(int left, int top, void *bitmap, int op);
  • putimage() function requires forr parameters. The first two parameters specifies the upper left corner of the image placed at (left,top). Third parameter is the address in memory from where the image is to be retrieved and last parameter specifies the operator which indicates that how the image should be displayed. Different- different putimage_ops are already enumerated in graphics.h header file as given below:
  • There are various putimage_ops that are also mentioned in graphics.h header file and the possible color values are from 0 to 4:
  • For better understanding go through the program:

Program

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd=DETECT, gm,size;

char *buff;

initgraph(&gd,&gm," ");

outtextxy(100,80,"Original image:");

rectangle(100,200,200,275);

size=imagesize(100,200,200,275);

buf=malloc(size);

getimage(100,200,200,275,buf);

outtextxy(100,320,"Captured image:");

putimage(100,340,buf,COPY_PUT);

getch();

closegraph();

}

The above program will capture an image that is rectangle from memory and display it at new position. imagesize() function returns the bytes required to store the image in memory. You have already studied imagesize() function in detail in the previous section. malloc() function will allocate the memory for the image and the pointer returned by the malloc() function will be stored in the variable buff. getimage() function here will capture the image from the memory.You have already studied getimage() function in detail in the previos section.and putimage function will display the image at position (100,340) as same as the original image.. The output of the above program is given below:

Output

c graphics