C++ getimage() and putimage() Function

- July 12, 2018
getimage and putimage in cpp


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<iostream>
#include<canio>
#include<graphics>
#include<stdio>
#include<stdlib>
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 <= 1) y = 1;
      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 <= 1) x = 1;
      break;
    }
    // put the image from ptr on next location
    putimage(x, y, ptr, COPY_PUT);
  }
  closegraph();
}

Leave your reply.
EmoticonEmoticon

 

Start typing and press Enter to search