Hi friends. Please tell me how to display a image file on the screen in C? If u r kind to me, send the code snippet.

Recommended Answers

All 5 Replies

#include <alloc.h>
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
#include <stdlib.h>

struct BMP
  char Type[2];           //File type. Set to "BM".
  unsigned long Size;     //Size in BYTES of the file.
  unsigned long Reserved;      //Reserved. Set to zero.
  unsigned long OffSet;   //Offset to the data.
  unsigned long headsize; //Size of rest of header. Set to 40.
  unsigned long Width;     //Width of bitmap in pixels.
  unsigned long Height;     //  Height of bitmap in pixels.
  unsigned int  Planes;    //Number of Planes. Set to 1.
  unsigned int  BitsPerPixel;       //Number of Bits per pixels.
  unsigned long Compression;   //Compression. Usually set to 0.
  unsigned long SizeImage;  //Size in bytes of the bitmap.
  unsigned long XPixelsPreMeter;     //Horizontal pixels per meter.
  unsigned long YPixelsPreMeter;     //Vertical pixels per meter.
  unsigned long ColorsUsed;   //Number of colors used.
  unsigned long ColorsImportant;  //Number of "important" colors.

int ShowBMP(int x, int y, char* FileName)
    int b,a;
    BMP Obj;

    unsigned char* Datas;
    int in=0;
    unsigned char c=0;
    FILE * fp;

    fp = fopen(FileName,"rb");
    printf("Error : Unable to open file ..");

    fread(&Obj, sizeof(Obj), 1, fp);
    if(Obj.BitsPerPixel!=4)  // This isn't a 16 color bmp we can read;
     printf("Error : File format not supported ..");
    Datas=(unsigned char*) calloc(Obj.Width/2+1, sizeof(unsigned char));
     fread(Datas, sizeof(unsigned char), Obj.Width/2, fp);
         c = (Datas[in] | 0x00) >>4;
         c = (Datas[in] | 0xF0) & 0x0F;
    free (Datas);
    return 1;
void main()
int color;
int gd , gm ;
gd = VGA ; gm = VGAHI;

ShowBMP(0,0,"tune.bmp"); /* Enter File Name Here */

I have found this over internet , i hope ,it will help You.

when i run the program it does'nt show any output screen
Help me to solve this???

help me to solve the problem while running the program??

The code above is from another time. The code does not look like it will work with many images today and then Windows.

At 11 years later, you should make a new discussion to ask your question, show your code and tell us the language and what you expected it to do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.