Advertisement
Guest User

Untitled

a guest
May 29th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4. #define LENGTH 640
  5. #define HEIGHT 480
  6.  
  7. typedef unsigned int uint;
  8.  
  9. int **img_array;
  10. FILE *image;
  11.  
  12. int main( void )
  13. {
  14.     srand ( time(NULL) );
  15.     uint rows, cols;
  16.     image = fopen("../myimage.raw", "wb");
  17.     img_array = (int**) malloc ( LENGTH * HEIGHT * sizeof(int) );
  18.     if(img_array == NULL)
  19.     {
  20.         free(image);
  21.         free(img_array);
  22.         exit(1);
  23.     }
  24.    
  25.     for(rows=0; rows<LENGTH; rows++)
  26.     {
  27.         for(cols=0; cols<HEIGHT; cols++)
  28.         {
  29.             img_array[rows][cols] = rand()%2;
  30.             fwrite(img_array, sizeof(int), sizeof(img_array), image);
  31.         }
  32.     }
  33.     printf("write complete.\n");
  34.     free(img_array);
  35.     fclose(image);
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement