1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
unsigned int inewr, inewg, inewb, ioldr, ioldg, ioldb // Creating Integers;
cout << "Enter R - G - B of Color to Replace: ";
cin >> ioldr >> ioldg >> ioldb; // Taking Integers of Old Color From User
cout << "Enter R - G - B of New: ";
cin >> inewr >> inewg >> inewb; // Taking Integers of New Color From User
// Type casting to char
unsigned char newr=inewr, newg=inewg, newb=inewb, oldr=ioldr, oldg=ioldr, oldb=ioldb;
cout << newr << " " << newg << " " << newb << endl; // Printing out characters
cout << oldr << " " << oldg << " " << oldb << endl;
// Checking color and writing in file...
for (int j=0; j<height; j++) {
for (int i=0; i<width*3; i+=3) {
b = mainarray[i][j];
g = mainarray[i+1][j];
r = mainarray[i+2][j];
if ( r==oldr && g==oldg && b==oldb) {
fout.write((char*) &newb, 1);
fout.write((char*) &newg, 1);
fout.write((char*) &newr, 1);
} else {
fout.write((char*) &b, 1);
fout.write((char*) &g, 1);
fout.write((char*) &r, 1);
}
}
}
|