C Language Chaos (i) 20 lines of code to generate BMP

Source: Internet
Author: User

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 (&AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.