A C++ to program show negative image.


#include<iostream>
#include<fstream.h>
#include<conio.h>
#include<string.h>
using namespace std;
struct pix {
unsigned char b,g,r; } pixel;
int L=255;//L is set to highest intensity per byte
char Header[54];
ifstream in;
ofstream out,out1;
int main() {
char infile[]=”d:\\bf.bmp”;
char outfile[]=”d:\\bf-neg.bmp”;
char imdata[]=”d:\\imdata.dat”;
in.open(infile,ios::in|ios::binary);
in.read((char*)(&Header),sizeof(Header));
out.open(infile,ios::in|ios::binary);
out.write((char*)(&Header),sizeof(Header));
out1.open(imdata,ios::out);
while(!in.eof()) {
in.read((char*) (&pixel),sizeof(pixel));
out1<<“ORIGINAL : “<<(int)pixel.r<<” “<<(int)pixel.g<<” “<<(int)pixel.b<<endl;
pixel.r=L-pixel.r;
pixel.g=L-pixel.g;
pixel.b=L-pixel.b;
out.write((char*) (&pixel),sizeof(pixel));
out1<<“MODIFIED (NEGATIVE) : “<<(int)pixel.r<<” “<<(int)pixel.g<<”
“<<(int)pixel.b<<endl; }
in.close();
getch(); }