In the process of learning graphic images, the simplest and most common format is BMP and PPM. The following gives the extremely thin code that generates BMP and then explains the BMP format.
1#include <stdio.h>2#include <stdlib.h>3 #defineW 2004 #defineH 2005 voidWritebmp (Char*img,Const Char*filename)6 {7 intL= (w*3+3)/4*4;8 intbmi[]= {l*h+ Wu,0, Wu, +, W,h,1|3*8<< -,0, L*h,0,0, -,0};9FILE *FP = fopen (filename,"WB");Tenfprintf (FP,"BM"); OneFwrite (&BMI, the,1, FP); AFwrite (IMG,1, l*H,FP); - fclose (FP); - } the intMain () - { - Charimg[w*h*3]; - for(intI=0; i<w*h*3; i++) Img[i]=rand ()% the; +Writebmp (IMG,"test.bmp"); -System"test.bmp"); + return 0; A}
The code above generates a BMP with camera graph with a width and height of 200. :
BMP format Description, to be continued ...
C Language Chaos (i) 20 lines of code to generate BMP