C Programming Articles

Submit Article
Home » Articles » C Programming » Computer GraphicsRSS Feeds

Program to display a 16 color bitmap

Posted By: Easy Tutor     Category: C Programming     Views: 7032

This program shows how to display a 16 color bitmap. In this program palettes are not used for bmp,hence all default 16 colors are used. If you know BMP structure you can try to add palettes.

Code for Program to display a 16 color bitmap in C Programming

#include <alloc.h>
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
#include <stdlib.h>
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+#define UL unsigned long#define UI unsigned int#define UC unsigned char//+-+-+-+-+-+-+-+-+-+-+-+-+-+< BMP Structures >+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
typedef struct
    char Type[2];
    UL Size;
    UI R1;
    UI R2;
    UL OffSet;
typedef struct
    UL headsize;
    UL Hlen;
    UL Vlen;
    UI planes;
    UI BPP;
    UL Method;
    UL BmpSize;
    UL HRes;
    UL VRes;
    UL Colors;
    UL IColors;
//+-+-+-+-+-+-+-+-+-+-+-+-+-< Display BMP >+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+int ShowBMP(int x, int y, char* FileName)
      int b,a;
      BMP1 Obj1;
      BMP2 Obj2;
      UC * Holder;
      UC c=0;
      FILE * fp;

      fp = fopen(FileName,"rb");
          return 0;
      fread(&Obj1, sizeof(Obj1), 1, fp);
      fread(&Obj2, sizeof(Obj2), 1, fp);
      if(Obj2.BPP!=4)  // This isn't a 16 color bmp we can read;
        return 0;
      Holder=(UC *) calloc(Obj2.Hlen/2+1, sizeof(UC));
        fread(Holder, sizeof(UC), Obj2.Hlen/2, fp);
            c = (Holder[in] | 0x00) >>4;
            c = (Holder[in] | 0xF0) & 0x0F;
      free (Holder);
      return 1;
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-< **** >+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+// Two bmp demo.bmp & demo1.bmp are provided.// open these bmp in windows paint & change.(do not change size of bmp)//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-< Main >+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+void main()
 int color,D=DETECT,E;
// registerfarbgidriver(EGAVGA_driver_far);
 if(!ShowBMP(0,0,"neeraj.bmp")) E=1;
 if(E) printf("\nError : Unable to open file.");
 else printf("Sucess !");

Didn't find what you were looking for? Find more on Program to display a 16 color bitmap Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program to display a 16 color bitmap is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Happy Programming :)

View All Articles

Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

Indranil Banerjee from India Comment on: Aug 09
Many many thanks to you..
God bless u.
email: indranil2121@gmail.com
I need more help from u.

View All Comments