Thursday, October 25, 2012

C code for Bit Map


/*BMP Attributes.C*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<graphics.h>

typedef struct bmp_header {
unsigned char ft[2];
unsigned long fsz;

unsigned int res1, res2;
unsigned long ofb, sz, wd, ht;
unsigned int npi, bpp;
unsigned long cps, isz, xres, yres;
unsigned long clru, clrimp;
 }TH;
TH *ihdr;

typedef struct RGBtag {
unsigned char blue, red, green, resv;
     }RGB;

RGB clrs[256], pal[256];

char buff[18];

void main()
{
int d= DETECT, m= VGAHI, xsize, ysize, pix, n, m1;
long int i, j;
FILE *imgf;
imgf= fopen("2.bmp", "rb");
if(imgf == NULL)
{
printf("\n\a ERROR");
exit(0);
}
clrscr();
fread(ihdr, sizeof(TH), 1, imgf);
printf("\n\t BMP FILE HEADER\n");
printf("\n1File Type: %c%c",ihdr->ft[0],ihdr->ft[1]);
printf("\n2 FILE SIZE = %ld bytes", ihdr -> fsz);
printf("\n3 RESERVED1 = %d ",ihdr -> res1);
printf("\n4 RESERVED2= %d ", ihdr-> res2);
printf("\n5 OFFSET TO START OF IMAGE= %ld bytes", ihdr->ofb);
printf("\n6 SIZE OF BITMAP INFO HEADER = %ld", ihdr->sz);
printf("\n7 IMAGE WIDTH = %ld pixels", ihdr->wd);
printf("\n8 IMAGE HEIGHT = %ld pixels ", ihdr->ht);
printf("\n9 no. of PLANES IN IMAGE = %d ", ihdr->npi);
printf("\n10 no of bits/ pixels= %d ", ihdr->bpp);
printf("\n11 TYPE OF COMPRESSION =%d", ihdr->cps);
printf("\n12 IMAGE SIZE= %ld bytes",ihdr->isz );
printf("\n13 HORIZONTAL RESOLUTION =%ld pixels/mtr", ihdr->xres);
printf("\n14 VERTICAL RESOLUTION = %ld pixel/mtr", ihdr->yres);
printf("\n15 NO of colours in image= %d", ihdr->clru);
printf("\n16 NO fo important colors %d ", ihdr->clrimp);
printf("\n RGB Values of a perticular pixel : \n\n");
printf("Row ?= ");
scanf("%d",&n);
printf("Column ?= ");
scanf("%d", &m1);
printf("\n ROW %d \n ",n);
printf("\n col. %d ", m1);
fseek(imgf, (n*sizeof(clrs))+(m1*sizeof(clrs)), SEEK_SET);
printf("\n R G B Resv. \n");
fread(&clrs, sizeof(clrs), 1, imgf);
printf("\n %d %d %d", clrs->blue, clrs-> green , clrs->resv);
getch();
}

No comments:

Post a Comment