Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

C++ getimage() and putimage() Function



In C++, the getimage() Function is used to save a bit image of the specified region displayed on the screen into memory. The general syntax of this function is as follows:


getimage (left, top, right, bottom, void for *bitmap);

Where:
left, top, right & bottom represent the integer data type values that define the region on the screen.
void for *bitmap represent the far pointer to store the captured image.

The storage capacity of far pointer is very high. It can be store data upto 1 MB. Generally, such type of modifier is used to capture and process images.

C++ putimage() Function

In C++, the putimage() function is used to put the bit image that is saved with getimage() function back to screen. The general syntax to call this function is as follows:


putimage(left, top, void for *bitamp);

Where:
left, top represent the "int" data type value to put the image to the specified upper left corner of the screen.

Example Program of getimage() and putimage()

The following C++ program moves an object on the screen Left, right, up and down by arrow keys until the ESC key is pressed.


#include
#include
#include
#include
#include
using namespace std;
main(void) {
int driver, mode, x = 0, y = 0;
driver = DETECT;
void far * ptr, * pb;
char ch;
initgraph( & driver, & mode, " ");
cleardevice();

// capture the blank image
getimage(x, y, 20, 20, pb);
circle(10, 10, 10);

// capture the circle into ptr
getimage(x, y, 20, 20, ptr);
while (ch != 27) {
ch = getch();

//put the blank image on previous location
putimage(x, y, pb, COPY_PUT);
switch (ch) {
case 'H': //for up arrow key
y -= 5;
if (y break;
case 'p'; //for down arrow key
y += 5;
if (y >= 460) y = 455;
break;
case 'M': //for right arrow key
x += 5;
if (x >= 620) y = 615;
break;
case 'K': //for left arrow key
x -= 5;
if (x break;
}
// put the image from ptr on next location
putimage(x, y, ptr, COPY_PUT);
}
closegraph();
}


This post first appeared on Programming Explain, please read the originial post: here

Share the post

C++ getimage() and putimage() Function

×

Subscribe to Programming Explain

Get updates delivered right to your inbox!

Thank you for your subscription

×