[C] 在屏幕上输出一个位图 →→→→→进入此内容的聊天室

来自 , 2020-08-09, 写在 C, 查看 116 次.
URL http://www.code666.cn/view/26505e04
  1. #include <graphics.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5.  
  6. #define ARROW_SIZE 10
  7.  
  8. void draw_arrow(int x, int y);
  9.  
  10. int main(void)
  11. {
  12.    /* request autodetection */
  13.    int gdriver = DETECT, gmode, errorcode;
  14.    void *arrow;
  15.    int x, y, maxx;
  16.    unsigned int size;
  17.  
  18.    /* initialize graphics and local variables */
  19.    initgraph(&gdriver, &gmode, "");
  20.  
  21.    /* read result of initialization */
  22.    errorcode = graphresult();
  23.    if (errorcode != grOk)  /* an error occurred */
  24.    {
  25.       printf("Graphics error: %s\n", grapherrormsg(errorcode));
  26.       printf("Press any key to halt:");
  27.       getch();
  28.       exit(1); /* terminate with an error code */
  29.    }
  30.  
  31.    maxx = getmaxx();
  32.    x = 0;
  33.    y = getmaxy() / 2;
  34.  
  35.    /* draw the image to be grabbed */
  36.    draw_arrow(x, y);
  37.  
  38.    /* calculate the size of the image */
  39.    size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE);
  40.  
  41.    /* allocate memory to hold the image */
  42.    arrow = malloc(size);
  43.  
  44.    /* grab the image */
  45.    getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow);
  46.  
  47.    /* repeat until a key is pressed */
  48.    while (!kbhit())
  49.    {
  50.       /* erase old image */
  51.       putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
  52.  
  53.       x += ARROW_SIZE;
  54.       if (x >= maxx)
  55.           x = 0;
  56.  
  57.       /* plot new image */
  58.       putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
  59.    }
  60.  
  61.    /* clean up */
  62.    free(arrow);
  63.    closegraph();
  64.    return 0;
  65. }
  66.  
  67. void draw_arrow(int x, int y)
  68. {
  69.    /* draw an arrow on the screen */
  70.    moveto(x, y);
  71.    linerel(4*ARROW_SIZE, 0);
  72.    linerel(-2*ARROW_SIZE, -1*ARROW_SIZE);
  73.    linerel(0, 2*ARROW_SIZE);
  74.    linerel(2*ARROW_SIZE, -1*ARROW_SIZE);
  75. }
  76.  

回复 "在屏幕上输出一个位图"

这儿你可以回复上面这条便签

captcha