Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void BMP_Image::writeToFile(std::string& str){
- dword extra,i,j=0;
- byte gelezenByte;
- ofstream ofile;
- ofile.open(str.c_str(),ios::binary);
- //leest variabele fileheader bitmap en schrijft naar file str
- ofile.write((char*)(&fh.bfType),sizeof(word));
- ofile.write((char*)(&fh.bfSize),sizeof(dword));
- ofile.write((char*)(&fh.bfReserved1),sizeof(word));
- ofile.write((char*)(&fh.bfReserved2),sizeof(word));
- ofile.write((char*)(&fh.bfOffBits),sizeof(dword));
- //leest variabele infohearder bitmap en schrijft naar file str
- ofile.write((char*)(&ih.biSize),sizeof(dword));
- ofile.write((char*)(&ih.biWidth),sizeof(dword));
- ofile.write((char*)(&ih.biHeight),sizeof(dword));
- ofile.write((char*)(&ih.biPlanes),sizeof(word));
- ofile.write((char*)(&ih.biBitCount),sizeof(word));
- ofile.write((char*)(&ih.biCompression),sizeof(dword));
- ofile.write((char*)(&ih.biSizeImage),sizeof(dword));
- ofile.write((char*)(&ih.biXpelsPerMeter),sizeof(dword));
- ofile.write((char*)(&ih.biYpelsPerMeter),sizeof(dword));
- ofile.write((char*)(&ih.biClrUsed),sizeof(dword));
- ofile.write((char*)(&ih.biClrImportant),sizeof(dword));
- //ih.biWidth=aantal pixels breedte
- //1 pixel=24 bits (voor 24bits bitmap)
- //dan dienen we nog te aligneren
- //dit door optellen van 32-(rest bij 32)
- //stel 72 bits heeft rest 8 maar dit is tgv 64, dus daarom 32-8
- //dan nog in bytes zetten 8bit=1byte
- extra=((32-(ih.biWidth*24)%32)/8)%4;
- //image uitschrijven
- for(i=0;i<ih.biHeight;i++){ //schrijven zolang er bytes zijn
- //bepalen welk byte te schrijven
- //na elke rij nullen toevoegen totdat veelvoud van 32 bits
- for(j=0;j<ih.biWidth;j++){
- gelezenByte=image[i][j].getRed();
- ofile.write((char*)&gelezenByte,sizeof(byte));
- gelezenByte=image[i][j].getGreen();
- ofile.write((char*)&gelezenByte,sizeof(byte));
- gelezenByte=image[i][j].getBlue();
- ofile.write((char*)&gelezenByte,sizeof(byte));
- }
- gelezenByte=0;
- ofile.write((char*)(&gelezenByte),extra*sizeof(byte));
- }
- ofile.close();
- }
Add Comment
Please, Sign In to add comment