Friday, December 28, 2012

PROGRAMS TO COPY IMAGE FILE

READ IMAGE FILE & COPY TO ANOTHER FILE:-



#include<iostream> 
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>

using namespace std;

int getimagedata(FILE*, FILE*);

void main()
{
FILE *f1,*f2;
f1=fopen("C:\\Users\\shubham\\Pictures\\photo.bmp","rb");
f2=fopen("C:\\Users\\shubham\\Pictures\\photo1.bmp","wb");

if(f1==NULL)
{
cout<<"file is empty";
}
else
{

while(!feof(f1))
{
char c=getimagedata(f1, f2);
cout<<c;
}
fclose(f1);
fclose(f2);

}

getch();
}

int getimagedata(FILE* f1,FILE* f2)
{
char ch;
ch=(char) getc(f1);
putc((char) ch,f2);
return(ch);
}

PROGRAMMING

READ IMAGE FILE & PRINT:-


#include<iostream>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>


using namespace std;


void main()
{
FILE *f1, *f2;
f1= fopen("NAME OF BMP IMAGE & ADDRESS","rb");
char c=NULL;
if(f1==NULL)
{
cout<<"file is empty";
}
else
{
while(c=getw(f1)!=EOF)
{
cout<< c;
}

}
fclose(f1);
getch();

}


READ IMAGE FILE & PRINT, BITMAP FILE HEADER & DIB HEADER:-



#include<iostream> 
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>

using namespace std;

int sizeofbmp(FILE *);
int rsvbmp1(FILE *);
int rsvbmp2(FILE*);
int startingaddressofbmp(FILE *);


int sizeofdib(FILE*);
int widthofdib(FILE*);
int heightofdib(FILE*);
int noofcolor(FILE*);
int noofbpp(FILE*);
int list(FILE*);
int imagesize(FILE*);
int hir(FILE*);
int vir(FILE*);
int colorpalette(FILE*);
int impcolor(FILE*);


void main()
{
FILE *f1=NULL;
f1=fopen("BMP IMAGE FILE NAME & ADDRESS","r");
char ch[2];
unsigned int a,b,c,d,e,h,i,j,k,n,o;
signed int f,g,l,m;

if(f1==NULL)
{
cout<<"file is empty";
}
else
{
fread(ch,2,1,f1);
   cout<<"BMP HEADER:-"<<endl;
cout<<"Signature:  "<<ch<<endl;
a=sizeofbmp(f1);
b=rsvbmp1(f1);
c=rsvbmp2(f1);
d=startingaddressofbmp(f1);

cout<<"DIB HEADER:-"<<endl;
e=sizeofdib(f1);
f=widthofdib(f1);
g=heightofdib(f1);
h=noofcolor(f1);
i=noofbpp(f1);
j=list(f1);
k=imagesize(f1);
l=hir(f1);
m=vir(f1);
n=colorpalette(f1);
o=impcolor(f1);


cout<<"size of bmp:  "<<a<<endl;
cout<<"reserve 1:  "<<b<<endl;
cout<<"reserve 2:  "<<c<<endl;
cout<<"Starting Address of BMP: "<<d<<endl;
cout<<"Size Of DIB HEADER:  "<<e<<endl;
cout<<"Width of dib in pixels:  "<<f<<endl;
cout<<"heigh of dib in pixels:  "<<g<<endl;
cout<<"no. of colors:  "<<h<<endl;
cout<<"no. of bits per pixel:  "<<i<<endl;
cout<<"list:  "<<j<<endl;
cout<<"image size:  "<<k<<endl;
cout<<"horizontal image resolution:  "<<l<<endl;
cout<<"Vertical image resolution:  "<<m<<endl;
cout<<"color palette:  "<<n<<endl;
cout<<"imp. colors used:  "<<o<<endl;
}

fclose(f1);
getch();
}

int sizeofbmp(FILE * f1)
{
unsigned int sizebmp;
fread(&sizebmp,4,1,f1);
//cout<<"size of bmp:  "<<sizebmp<<endl;
return(sizebmp);

}

int rsvbmp1(FILE* f1)
{
unsigned int reservebmp1;
fread(&reservebmp1,2,1,f1);
//cout<<"reserve 1:  "<<reservebmp1<<endl;
return(reservebmp1);
}

int rsvbmp2(FILE* f1)
{
unsigned int reservebmp2;
fread(&reservebmp2,2,1,f1);
//cout<<"reserve 2:  "<<reservebmp2<<endl;
return(reservebmp2);
}

int startingaddressofbmp(FILE*f1)
{
unsigned int saobmp;
fread(&saobmp,4,1,f1);
//cout<<"Starting Address of BMP: "<<saobmp<<endl;
return(saobmp);
}



int sizeofdib(FILE*f1)
{
unsigned int sizebmp;
fread(&sizebmp,4,1,f1);
//cout<<"Size Of DIB HEADER:  "<<sizebmp<<endl;
return(sizebmp);
}
int widthofdib(FILE*f1)
{
signed int wdtbmp;
fread(&wdtbmp,4,1,f1);
//cout<<"Width of dib in pixels:  "<<wdtbmp<<endl;
return(wdtbmp);
}

int heightofdib(FILE*f1)
{
signed int hgtbmp;
fread(&hgtbmp,4,1,f1);
//cout<<"heigh of dib in pixels:  "<<hgtbmp<<endl;
return(hgtbmp);
}

int noofcolor(FILE*f1)
{
unsigned int color;
fread(&color,2,1,f1);
//cout<<"no. of colors:  "<<color<<endl;
return(color);

}


int noofbpp(FILE*f1)
{
unsigned int bpp;
fread(&bpp,2,1,f1);
//cout<<"no. of bits per pixel:  "<<bpp<<endl;
return(bpp);

}


int list(FILE*f1)
{
unsigned int lst;
fread(&lst,4,1,f1);
//cout<<"list:  "<<lst<<endl;
return(lst);
}


int imagesize(FILE*f1)
{
unsigned int imgsz;
fread(&imgsz,4,1,f1);
//cout<<"image size:  "<<imgsz<<endl;
return(imgsz);
}


int hir(FILE*f1)
{
signed rsl;
fread(&rsl,4,1,f1);
//cout<<"horizontal image resolution:  "<<rsl<<endl;
return(rsl);

}


int vir(FILE*f1)
{
signed int rsl1;
fread(&rsl1,4,1,f1);
//cout<<"Vertical image resolution:  "<<rsl1<<endl;
return(rsl1);
}


int colorpalette(FILE*f1)
{
unsigned int cp;
fread(&cp,4,1,f1);
//cout<<"color palette:  "<<cp<<endl;
return(cp);
}

int impcolor(FILE*f1)
{
unsigned int impc;
fread(&impc,4,1,f1);
//cout<<"imp. colors used:  "<<impc<<endl;
return(impc);
}



Thursday, December 27, 2012

BITMAP FILE FORMAT

1.  Bitmap File Format is also known as Bitmap Image File Or Device Independent Bitmap( DIB )  
     File Format.
2.  Raster File Format is used to store Bitmap Digital Images.
3.  We can exchanging Bitmaps between the Devices. 


FILE STRUCTURE:-




BITMAP FILE HEADER:-

 Bitmap File Header is of 14 Bytes.
 This is distinguished given below:-

  






DIB HEADER ( BITMAP INFORMATION HEADER ):-


 BITMAP INFO HEADER:-







PIXEL FORMAT:-


In a Bitmap Image File on a Disk Or a Bitmap Image in Memory, the Pixels can be defined by a varying numbers of Bits.