summaryrefslogtreecommitdiff
path: root/cd/test/screencapture.c
blob: 1ac8d2cc52d1fa2a9be8835c8839890e8b03c8ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <stdlib.h>
#include <cd.h>
#include <cdnative.h>
#include <im.h>

void main()
{
  cdCanvas *cd_canvas;
  unsigned char *red, *green, *blue;
  int width, height, size;

  cd_canvas = cdCreateCanvas(CD_NATIVEWINDOW, NULL);
  if (!cd_canvas)
  {
    printf("Error creating canvas.\n");
    return;
  }        
  
  cdActivate(cd_canvas);

  cdGetCanvasSize(&width, &height, NULL, NULL);
  size = width * height;
  red = (unsigned char*)calloc(size, 1);
  green = (unsigned char*)calloc(size, 1);
  blue = (unsigned char*)calloc(size, 1);

  cdGetImageRGB(red, green, blue, 0, 0, width, height);
  imSaveRGB(width, height, IM_JPG|IM_COMPRESSED, red, green, blue, "scap.jpg");

  cdKillCanvas(cd_canvas);
  
  free(red);
  free(green);
  free(blue);
}