BITMAP FILE FORMAT
Tuesday, September 17, 2013
Thursday, January 3, 2013
CHANNEL SAPARATION ( RGB )...
READ AND COPY OF 24 BIT BMP IMAGE IN RGB ( RED, BLUE & GREEN ):-
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
using namespace std;
int getWidthInPixels(FILE*);
int getHeightInPixels(FILE*);
int StartingAddressofBMP(FILE*);
int WidthInPixels=0, HeightInPixels=0;
int WidthInBytes=0, HeightInBytes=0;
int forColorMatrixHeight=0;
int forColorMatrixWidth=0;
int RedColorArrayf(FILE*,FILE* , unsigned char*, int);
int GreenColorArrayf(FILE*,FILE*, unsigned char*, int);
int BlueColorArrayf(FILE*,FILE*, unsigned char*, int);
int ReadCopyHeaderred(FILE*, FILE*);
int ReadCopyHeaderblue(FILE*, FILE*);
int ReadCopyHeadergreen(FILE*, FILE*);
void main()
{
FILE *f1=NULL;
FILE* f2=NULL;
FILE* f3=NULL;
FILE* f4=NULL;
f1=fopen("C:\\Users\\shubham\\Downloads\\parrot-big.bmp","rb");
f2=fopen("C:\\Users\\shubham\\Downloads\\parrot-copyred.bmp","wb ");
f3=fopen("C:\\Users\\shubham\\Downloads\\parrot-copyblue.bmp","wb ");
f4=fopen("C:\\Users\\shubham\\Downloads\\parrot-copygreen.bmp","wb ");
char Red;
if(f1==NULL)
{
cout<<"file is empty";
}
else
{
unsigned int StartingImageAddress =StartingAddressofBMP(f1);
WidthInPixels=getWidthInPixels(f1);
WidthInBytes=3*WidthInPixels;
HeightInPixels=getHeightInPixels(f1);
HeightInBytes=3*HeightInPixels;
forColorMatrixHeight=HeightInBytes/3;
forColorMatrixWidth=WidthInBytes/3;
unsigned char* RedColorArray= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth);
unsigned char* BlueColorArray= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth);
unsigned char* GreenColorArray= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth);
cout<<"Starting Address Of BMP: "<<StartingImageAddress<<endl;
cout<<"Width of Image in Bytes: "<<WidthInBytes<<endl;
cout<<"height of Image in Bytes: "<<HeightInBytes<<endl;
ReadCopyHeaderred(f1, f2);
RedColorArrayf(f1,f2, RedColorArray, StartingImageAddress);
ReadCopyHeaderblue(f1, f3);
BlueColorArrayf(f1,f3, BlueColorArray,StartingImageAddress);
ReadCopyHeadergreen(f1, f4);
GreenColorArrayf(f1,f4, GreenColorArray, StartingImageAddress);
free(RedColorArray);
free(BlueColorArray);
free(GreenColorArray);
}
fclose(f1);
fclose(f2);
getch();
}
int ReadCopyHeaderred(FILE* f1,FILE* f2)//copy
{
char character;
int c=0;
fseek(f1,0,SEEK_SET);
character=(char)fgetc(f1);
for(int m=0; m<53; m++)
{
(char)putc(character,f2);
character=(char)fgetc(f1);
cout<<character;
c++;
}
cout<<"count: "<<c<<endl;
return(character);
}
int ReadCopyHeaderblue(FILE* f1,FILE* f3)//copy
{
char character;
int c=0;
fseek(f1,0,SEEK_SET);
character=(char)fgetc(f1);
for(int m=0; m<53; m++)
{
(char)putc(character,f3);
character=(char)fgetc(f1);
cout<<character;
c++;
}
cout<<"count: "<<c<<endl;
return(character);
}
int ReadCopyHeadergreen(FILE* f1,FILE* f4)//copy
{
char character;
int c=0;
fseek(f1,0,SEEK_SET);
character=(char)fgetc(f1);
for(int m=0; m<53; m++)
{
(char)putc(character,f4);
character=(char)fgetc(f1);
cout<<character;
c++;
}
cout<<"count: "<<c<<endl;
return(character);
}
int StartingAddressofBMP(FILE*f1)
{
rewind(f1);
fseek(f1,10,0);
unsigned int saobmp;
fread(&saobmp,4,1,f1);
return(saobmp);
}
int getWidthInPixels(FILE*f1)
{
rewind(f1);
fseek(f1,18,0);
signed int wdtbmp;
fread(&wdtbmp,4,1,f1);
return(wdtbmp);
}
int getHeightInPixels(FILE*f1)
{
rewind(f1);
fseek(f1,22,0);
signed int hgtbmp;
fread(&hgtbmp,4,1,f1);
return(hgtbmp);
}
int RedColorArrayf(FILE* f1,FILE* f2, unsigned char* RedColorArray, int StartingImageAddress)
{
fseek(f1,StartingImageAddress,SEEK_SET);
char ch;
int j=0;
int c=0;
fread(&ch, 1, 1, f1);
fwrite(&ch,1,3,f2);
while(!feof(f1))
{
RedColorArray[j] =ch;
c++;
StartingImageAddress = StartingImageAddress + 3;
fseek(f1,StartingImageAddress,SEEK_SET);
fread(&ch, 1, 1, f1);
fwrite(&ch,1,3,f2);
}
cout<<endl<<"Size Of ReD Image Data: "<<c<<endl;
return(ch);
}
int BlueColorArrayf(FILE* f1,FILE* f3, unsigned char* BlueColorArray, int StartingImageAddress)
{
StartingImageAddress += 1 ;
fseek(f1,StartingImageAddress,SEEK_SET);
fseek(f3,StartingImageAddress,SEEK_SET);
char ch1;
int k=0;
int c=0;
fread(&ch1,1,1,f1);
fwrite(&ch1,1,3,f3);
while(!feof(f1))
{
BlueColorArray[k] =ch1;
c++;
StartingImageAddress=StartingImageAddress + 3;
fseek(f1,StartingImageAddress,SEEK_SET);
fread(&ch1, 1, 1, f1);
fwrite(&ch1,1,3,f3);
}
cout<<"Size Of Blue Image Data: "<<c<<endl;
return(ch1);
}
int GreenColorArrayf(FILE* f1,FILE* f4, unsigned char* GreenColorArray,int StartingImageAddress)
{
StartingImageAddress +2;
fseek(f1,StartingImageAddress,SEEK_SET);
fseek(f1,StartingImageAddress,SEEK_SET);
char ch2;
int l=0;
int c=0;
fread(&ch2,1,1,f1);
fwrite(&ch2,1,3,f4);
while(!feof(f1))
{
GreenColorArray[l] =ch2;
c++;
StartingImageAddress=StartingImageAddress + 3;
fseek(f1,StartingImageAddress,SEEK_SET);
fread(&ch2, 1, 1, f1);
fwrite(&ch2,1,3,f4);
}
cout<<"Size Of Green Image Data: "<<c;
return(ch2);
}
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
using namespace std;
int getWidthInPixels(FILE*);
int getHeightInPixels(FILE*);
int StartingAddressofBMP(FILE*);
int WidthInPixels=0, HeightInPixels=0;
int WidthInBytes=0, HeightInBytes=0;
int forColorMatrixHeight=0;
int forColorMatrixWidth=0;
int RedColorArrayf(FILE*,FILE* , unsigned char*, int);
int GreenColorArrayf(FILE*,FILE*, unsigned char*, int);
int BlueColorArrayf(FILE*,FILE*, unsigned char*, int);
int ReadCopyHeaderred(FILE*, FILE*);
int ReadCopyHeaderblue(FILE*, FILE*);
int ReadCopyHeadergreen(FILE*, FILE*);
void main()
{
FILE *f1=NULL;
FILE* f2=NULL;
FILE* f3=NULL;
FILE* f4=NULL;
f1=fopen("C:\\Users\\shubham\\Downloads\\parrot-big.bmp","rb");
f2=fopen("C:\\Users\\shubham\\Downloads\\parrot-copyred.bmp","wb ");
f3=fopen("C:\\Users\\shubham\\Downloads\\parrot-copyblue.bmp","wb ");
f4=fopen("C:\\Users\\shubham\\Downloads\\parrot-copygreen.bmp","wb ");
char Red;
if(f1==NULL)
{
cout<<"file is empty";
}
else
{
unsigned int StartingImageAddress =StartingAddressofBMP(f1);
WidthInPixels=getWidthInPixels(f1);
WidthInBytes=3*WidthInPixels;
HeightInPixels=getHeightInPixels(f1);
HeightInBytes=3*HeightInPixels;
forColorMatrixHeight=HeightInBytes/3;
forColorMatrixWidth=WidthInBytes/3;
unsigned char* RedColorArray= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth);
unsigned char* BlueColorArray= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth);
unsigned char* GreenColorArray= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth);
cout<<"Starting Address Of BMP: "<<StartingImageAddress<<endl;
cout<<"Width of Image in Bytes: "<<WidthInBytes<<endl;
cout<<"height of Image in Bytes: "<<HeightInBytes<<endl;
ReadCopyHeaderred(f1, f2);
RedColorArrayf(f1,f2, RedColorArray, StartingImageAddress);
ReadCopyHeaderblue(f1, f3);
BlueColorArrayf(f1,f3, BlueColorArray,StartingImageAddress);
ReadCopyHeadergreen(f1, f4);
GreenColorArrayf(f1,f4, GreenColorArray, StartingImageAddress);
free(RedColorArray);
free(BlueColorArray);
free(GreenColorArray);
}
fclose(f1);
fclose(f2);
getch();
}
int ReadCopyHeaderred(FILE* f1,FILE* f2)//copy
{
char character;
int c=0;
fseek(f1,0,SEEK_SET);
character=(char)fgetc(f1);
for(int m=0; m<53; m++)
{
(char)putc(character,f2);
character=(char)fgetc(f1);
cout<<character;
c++;
}
cout<<"count: "<<c<<endl;
return(character);
}
int ReadCopyHeaderblue(FILE* f1,FILE* f3)//copy
{
char character;
int c=0;
fseek(f1,0,SEEK_SET);
character=(char)fgetc(f1);
for(int m=0; m<53; m++)
{
(char)putc(character,f3);
character=(char)fgetc(f1);
cout<<character;
c++;
}
cout<<"count: "<<c<<endl;
return(character);
}
int ReadCopyHeadergreen(FILE* f1,FILE* f4)//copy
{
char character;
int c=0;
fseek(f1,0,SEEK_SET);
character=(char)fgetc(f1);
for(int m=0; m<53; m++)
{
(char)putc(character,f4);
character=(char)fgetc(f1);
cout<<character;
c++;
}
cout<<"count: "<<c<<endl;
return(character);
}
int StartingAddressofBMP(FILE*f1)
{
rewind(f1);
fseek(f1,10,0);
unsigned int saobmp;
fread(&saobmp,4,1,f1);
return(saobmp);
}
int getWidthInPixels(FILE*f1)
{
rewind(f1);
fseek(f1,18,0);
signed int wdtbmp;
fread(&wdtbmp,4,1,f1);
return(wdtbmp);
}
int getHeightInPixels(FILE*f1)
{
rewind(f1);
fseek(f1,22,0);
signed int hgtbmp;
fread(&hgtbmp,4,1,f1);
return(hgtbmp);
}
int RedColorArrayf(FILE* f1,FILE* f2, unsigned char* RedColorArray, int StartingImageAddress)
{
fseek(f1,StartingImageAddress,SEEK_SET);
char ch;
int j=0;
int c=0;
fread(&ch, 1, 1, f1);
fwrite(&ch,1,3,f2);
while(!feof(f1))
{
RedColorArray[j] =ch;
c++;
StartingImageAddress = StartingImageAddress + 3;
fseek(f1,StartingImageAddress,SEEK_SET);
fread(&ch, 1, 1, f1);
fwrite(&ch,1,3,f2);
}
cout<<endl<<"Size Of ReD Image Data: "<<c<<endl;
return(ch);
}
int BlueColorArrayf(FILE* f1,FILE* f3, unsigned char* BlueColorArray, int StartingImageAddress)
{
StartingImageAddress += 1 ;
fseek(f1,StartingImageAddress,SEEK_SET);
fseek(f3,StartingImageAddress,SEEK_SET);
char ch1;
int k=0;
int c=0;
fread(&ch1,1,1,f1);
fwrite(&ch1,1,3,f3);
while(!feof(f1))
{
BlueColorArray[k] =ch1;
c++;
StartingImageAddress=StartingImageAddress + 3;
fseek(f1,StartingImageAddress,SEEK_SET);
fread(&ch1, 1, 1, f1);
fwrite(&ch1,1,3,f3);
}
cout<<"Size Of Blue Image Data: "<<c<<endl;
return(ch1);
}
int GreenColorArrayf(FILE* f1,FILE* f4, unsigned char* GreenColorArray,int StartingImageAddress)
{
StartingImageAddress +2;
fseek(f1,StartingImageAddress,SEEK_SET);
fseek(f1,StartingImageAddress,SEEK_SET);
char ch2;
int l=0;
int c=0;
fread(&ch2,1,1,f1);
fwrite(&ch2,1,3,f4);
while(!feof(f1))
{
GreenColorArray[l] =ch2;
c++;
StartingImageAddress=StartingImageAddress + 3;
fseek(f1,StartingImageAddress,SEEK_SET);
fread(&ch2, 1, 1, f1);
fwrite(&ch2,1,3,f4);
}
cout<<"Size Of Green Image Data: "<<c;
return(ch2);
}
CHANNEL SAPARATION (RGB)
READING OF 24 BIT BMP IMAGE IN RGB ( RED, BLUE & GREEN ):-
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
using namespace std;
int getWidthInPixels(FILE*);
int getHeightInPixels(FILE*);
int StartingAddressofBMP(FILE*);
//void getImageData(FILE*, unsigned char*, unsigned char*, unsigned char*, unsigned char*);
int WidthInPixels=0, HeightInPixels=0;
int WidthInBytes=0, HeightInBytes=0;
int forColorMatrixHeight=0;
int forColorMatrixWidth=0;
int RedColorArrayf(FILE*, unsigned char*);
int GreenColorArrayf(FILE*, unsigned char*);
int BlueColorArrayf(FILE*, unsigned char*);
void main()
{
FILE *f1=NULL;
f1=fopen("C:\\Users\\shubham\\Downloads\\red24bit.bmp","rb");
//unsigned char* imageData=(unsigned char*)malloc(HeightInBytes*WidthInBytes);
unsigned int StartingAddress;
char Red;
if(f1==NULL)
{
cout<<"file is empty";
}
else
{
StartingAddress =StartingAddressofBMP(f1);
WidthInPixels=getWidthInPixels(f1);
WidthInBytes=3*WidthInPixels;
HeightInPixels=getHeightInPixels(f1);
HeightInBytes=3*HeightInPixels;
forColorMatrixHeight=HeightInBytes/3;
forColorMatrixWidth=WidthInBytes/3;
unsigned char* RedColorArray= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth);
unsigned char* BlueColorArray= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth);
unsigned char* GreenColorArray= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth);
cout<<"Starting Address Of BMP: "<<StartingAddress<<endl;
cout<<"Width of Image in Bytes: "<<WidthInBytes<<endl;
cout<<"height of Image in Bytes: "<<HeightInBytes<<endl;
RedColorArrayf(f1, RedColorArray);
BlueColorArrayf(f1, BlueColorArray);
GreenColorArrayf(f1, GreenColorArray);
//cout<<"Red Image Data: "<<Red;
free(RedColorArray);
free(BlueColorArray);
free(GreenColorArray);
}
//free(imageData);
fclose(f1);
getch();
}
int StartingAddressofBMP(FILE*f1)
{
rewind(f1);
//int saddress;
fseek(f1,10,0);
unsigned int saobmp;
fread(&saobmp,4,1,f1);
return(saobmp);
}
int getWidthInPixels(FILE*f1)
{
rewind(f1);
fseek(f1,18,0);
signed int wdtbmp;
fread(&wdtbmp,4,1,f1);
//cout<<"Width of dib in pixels: "<<wdtbmp<<endl;
return(wdtbmp);
}
int getHeightInPixels(FILE*f1)
{
rewind(f1);
fseek(f1,22,0);
signed int hgtbmp;
fread(&hgtbmp,4,1,f1);
//cout<<"heigh of dib in pixels: "<<hgtbmp<<endl;
return(hgtbmp);
}
int RedColorArrayf(FILE* f1, unsigned char* RedColorArray)
{
int StartingImageData=54;
fseek(f1,StartingImageData,SEEK_SET);
char ch;
int j=0;
int c=0;
fread(&ch, 1, 1, f1);
while(!feof(f1))
{
RedColorArray[j] =ch;
c++;
StartingImageData = StartingImageData + 3;
fseek(f1,StartingImageData,SEEK_SET);
fread(&ch, 1, 1, f1);
}
cout<<"Size Of ReD Image Data: "<<c<<endl;
return(ch);
}
int BlueColorArrayf(FILE* f1, unsigned char* BlueColorArray)
{
int StartingImageData=55;
fseek(f1,StartingImageData,SEEK_SET);
char ch1;
int k=0;
int c=0;
//unsigned char* RedColorData= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth );
fread(&ch1,1,1,f1);
while(!feof(f1))
{
BlueColorArray[k] =ch1;
c++;
StartingImageData=StartingImageData+ 3;
fread(&ch1, 1, 1, f1);
}
cout<<"Size Of Blue Image Data: "<<c<<endl;
return(ch1);
}
int GreenColorArrayf(FILE* f1, unsigned char* GreenColorArray)
{
int StartingImageData=56;
fseek(f1,StartingImageData,SEEK_SET);
char ch2;
int l=0;
int c=0;
//unsigned char* RedColorData= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth );
fread(&ch2,1,1,f1);
while(!feof(f1))
{
GreenColorArray[l] =ch2;
c++;
StartingImageData=StartingImageData+ 3;
fread(&ch2, 1, 1, f1);
}
cout<<"Size Of Green Image Data: "<<c;
return(ch2);
}
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
using namespace std;
int getWidthInPixels(FILE*);
int getHeightInPixels(FILE*);
int StartingAddressofBMP(FILE*);
//void getImageData(FILE*, unsigned char*, unsigned char*, unsigned char*, unsigned char*);
int WidthInPixels=0, HeightInPixels=0;
int WidthInBytes=0, HeightInBytes=0;
int forColorMatrixHeight=0;
int forColorMatrixWidth=0;
int RedColorArrayf(FILE*, unsigned char*);
int GreenColorArrayf(FILE*, unsigned char*);
int BlueColorArrayf(FILE*, unsigned char*);
void main()
{
FILE *f1=NULL;
f1=fopen("C:\\Users\\shubham\\Downloads\\red24bit.bmp","rb");
//unsigned char* imageData=(unsigned char*)malloc(HeightInBytes*WidthInBytes);
unsigned int StartingAddress;
char Red;
if(f1==NULL)
{
cout<<"file is empty";
}
else
{
StartingAddress =StartingAddressofBMP(f1);
WidthInPixels=getWidthInPixels(f1);
WidthInBytes=3*WidthInPixels;
HeightInPixels=getHeightInPixels(f1);
HeightInBytes=3*HeightInPixels;
forColorMatrixHeight=HeightInBytes/3;
forColorMatrixWidth=WidthInBytes/3;
unsigned char* RedColorArray= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth);
unsigned char* BlueColorArray= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth);
unsigned char* GreenColorArray= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth);
cout<<"Starting Address Of BMP: "<<StartingAddress<<endl;
cout<<"Width of Image in Bytes: "<<WidthInBytes<<endl;
cout<<"height of Image in Bytes: "<<HeightInBytes<<endl;
RedColorArrayf(f1, RedColorArray);
BlueColorArrayf(f1, BlueColorArray);
GreenColorArrayf(f1, GreenColorArray);
//cout<<"Red Image Data: "<<Red;
free(RedColorArray);
free(BlueColorArray);
free(GreenColorArray);
}
//free(imageData);
fclose(f1);
getch();
}
int StartingAddressofBMP(FILE*f1)
{
rewind(f1);
//int saddress;
fseek(f1,10,0);
unsigned int saobmp;
fread(&saobmp,4,1,f1);
return(saobmp);
}
int getWidthInPixels(FILE*f1)
{
rewind(f1);
fseek(f1,18,0);
signed int wdtbmp;
fread(&wdtbmp,4,1,f1);
//cout<<"Width of dib in pixels: "<<wdtbmp<<endl;
return(wdtbmp);
}
int getHeightInPixels(FILE*f1)
{
rewind(f1);
fseek(f1,22,0);
signed int hgtbmp;
fread(&hgtbmp,4,1,f1);
//cout<<"heigh of dib in pixels: "<<hgtbmp<<endl;
return(hgtbmp);
}
int RedColorArrayf(FILE* f1, unsigned char* RedColorArray)
{
int StartingImageData=54;
fseek(f1,StartingImageData,SEEK_SET);
char ch;
int j=0;
int c=0;
fread(&ch, 1, 1, f1);
while(!feof(f1))
{
RedColorArray[j] =ch;
c++;
StartingImageData = StartingImageData + 3;
fseek(f1,StartingImageData,SEEK_SET);
fread(&ch, 1, 1, f1);
}
cout<<"Size Of ReD Image Data: "<<c<<endl;
return(ch);
}
int BlueColorArrayf(FILE* f1, unsigned char* BlueColorArray)
{
int StartingImageData=55;
fseek(f1,StartingImageData,SEEK_SET);
char ch1;
int k=0;
int c=0;
//unsigned char* RedColorData= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth );
fread(&ch1,1,1,f1);
while(!feof(f1))
{
BlueColorArray[k] =ch1;
c++;
StartingImageData=StartingImageData+ 3;
fread(&ch1, 1, 1, f1);
}
cout<<"Size Of Blue Image Data: "<<c<<endl;
return(ch1);
}
int GreenColorArrayf(FILE* f1, unsigned char* GreenColorArray)
{
int StartingImageData=56;
fseek(f1,StartingImageData,SEEK_SET);
char ch2;
int l=0;
int c=0;
//unsigned char* RedColorData= (unsigned char*)malloc(forColorMatrixHeight * forColorMatrixWidth );
fread(&ch2,1,1,f1);
while(!feof(f1))
{
GreenColorArray[l] =ch2;
c++;
StartingImageData=StartingImageData+ 3;
fread(&ch2, 1, 1, f1);
}
cout<<"Size Of Green Image Data: "<<c;
return(ch2);
}
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);
}
#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>
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);
}
#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:-
Subscribe to:
Posts (Atom)