944,054 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3532
  • C++ RSS
Jul 18th, 2007
0

Inverting 24-bit bitmap using fstream c++

Expand Post »
Hello!
I need to invert a 24-bit bmp image from right to left, and from top to bottom. I know how to invert colours, but not the position. I only know fstream to open and close files. This is what I did (below). Please let me know where I am wrong, or maybe other easiter things than fstream that i can use? Really appreciate any help!!!


void ReverseBMP::reverseBitmap()
{
string originalBMP;
string reversedBMP;
cout<<"Please specify the name of original file. Include extension .bmp "<<endl;
cin>>originalBMP;
cout<<"Please specify the name of reversed file. Include extension .bmp "<<endl;
cin>>reversedBMP;

ifstream original_file;
original_file.open(originalBMP.c_str(), ios::in|ios::binary);

ofstream reversed_file(reversedBMP.c_str(), ios::binary|ios::out);

char c;

//finding the size of the existing bitmap file
original_file.seekg(0,ios::end);
long size_of_original = original_file.tellg();

//putting cursor back to beginning in original file
original_file.seekg(0,ifstream::beg);

int count=0;
int cursor_position = 0;
reversed_file.seekp(0, ofstream::beg);

while(!original_file.eof())
{
original_file.read(&c, sizeof(char));

// Reading header of the original file - the first 54 characters starting at 0
if(count < 54)
{
reversed_file.put(c);
count++;
}


else
{
reversed_file.seekp(cursor_position, ios::end);
reversed_file.put(c);
reversed_file.put(c);
reversed_file.put(c);
cursor_position++;
count++;
}


}

original_file.close();
reversed_file.close();

}
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
Mylena is offline Offline
30 posts
since Jul 2007
Jul 18th, 2007
0

Re: Inverting 24-bit bitmap using fstream c++

Can't you use a bmp library.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 18th, 2007
0

Re: Inverting 24-bit bitmap using fstream c++

oh, thanks, i didn't know there's a bmp library... i'll do someresearch then!
Reputation Points: 10
Solved Threads: 1
Light Poster
Mylena is offline Offline
30 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ PER encoders
Next Thread in C++ Forum Timeline: Permutation





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC