| | |
Inverting 24-bit bitmap using fstream c++
![]() |
•
•
Join Date: Jul 2007
Posts: 30
Reputation:
Solved Threads: 1
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();
}
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
- How to draw a line in a VB.NET form? (VB.NET)
- fstream Tutorial (C++)
- RLE with a grayscale bitmap (Java)
Other Threads in the C++ Forum
- Previous Thread: Bank Account Class
- Next Thread: Permutation
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error faq file forms fstream function functions game givemetehcodez graph gui hash homeworkhelp homeworkhelper iamthwee ifpug ifstream infinite input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template templates test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets






