3.10 setviewport

功能:

这个函数用于设置当前视图。并且,将坐标原点移动到新的视图的 (0, 0) 位置。


声明:

void setviewport(
    int left,
    int top,
    int right,
    int bottom,
    int clip = 1,
    PIMAGE pimg = NULL
);



参数:

left

视图的左部 x 坐标。

top

视图的上部 y 坐标。(left, top) 将成为新的原点。

right

视图的右部 x 坐标。

bottom

视图的下部 y 坐标。(right-1, bottom-1) 是视图的右下角坐标。

clip

视图的裁剪标志。如果为真,所有超出视图区域的绘图都会被裁剪掉。

pimg

要设置的图片


返回值:

(无)


示例:

#include "graphics.h"
int main()
{
    initgraph(640, 480);
    setviewport(100, 100, 200, 200);
    rectangle(0, 0, 200, 200);
    getch();
    closegraph();
    return 0;
}


注意:

右端点和下端点取不到,上端点和左端点能取到。另外,这函数的最后一个参数为一个IMAGE*的指针,是一个可选参数,如果不填,则设置到当前页。如果填上,则设置到指定的IMAGE。