I am writing a program to make pictures into their negative. But I do not know how to open the bitmap file, I don't know if I should open it as a binary, when I try to my security coding kicks in, and when I open as ios::out my security coding doesn't kick in and it shows me allocated garbage. Please help.
#include <iostream>
#include <cstdlib>
#include <windows.h> // Sleep
#include <fstream> // fstream
#include <istream> // seekg, seekp, read, write
#include <iomanip> // setfill, setw
using namespace std;
struct Image
{
char imageName[50];
int sizeFile,
offSet,
imageWidth,
imageHeight;
};
//void change2Negative();
void read4mFile(fstream &, Image &);
void displayFileInfo(const Image &);
int main()
{
Image bmp;
cout << setfill(' ') << setw(28) << " " << "Negative Picture Creator" << endl;
cout << setfill('-') << setw(80) << "-" << endl;
endl(cout);
cout << "Please enter the name of the file: ";
cin.getline(bmp.imageName, 50);
endl(cout);
fstream outFile;
outFile.open(bmp.imageName, ios::binary);
if(outFile.is_open())
{
read4mFile(outFile, bmp);
displayFileInfo(bmp);
outFile.close();
}
else
{
cout << "The file named " << bmp.imageName << " was not found! Program will shutdown." << endl;
Sleep(1500);
return 0;
}
system("PAUSE");
return EXIT_SUCCESS;
}
void read4mFile(fstream &dFile, Image &dInfo)
{
dFile.seekg(0, ios::beg);
dFile.seekg(2);
dFile.read(reinterpret_cast<char *>(&dInfo.sizeFile), sizeof(int));
dFile.seekg(10);
dFile.read(reinterpret_cast<char *>(&dInfo.offSet), sizeof(int));
dFile.seekg(18);
dFile.read(reinterpret_cast<char *>(&dInfo.imageWidth), sizeof(int));
dFile.seekg(22);
dFile.read(reinterpret_cast<char *>(&dInfo.imageHeight), sizeof(int));
}
void displayFileInfo(const Image &dInfo)
{
cout << "File Name: " << dInfo.imageName <<endl;
cout << "File Size: " << dInfo.sizeFile <<endl;
cout << "File Offset: " << dInfo.offSet <<endl;
cout << "File Width: " << dInfo.imageWidth <<endl;
cout << "File Height: " << dInfo.imageHeight <<endl;
}
I am trying to get all my information from a 24 bit True color bmp.