Advertisement
Alienguard

Bitmap.cpp

Jun 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <fstream>
  2. #include "Bitmap.h"
  3. #include "BitmapInfoHeader.h"
  4. #include "BitmapFileHeader.h"
  5.  
  6. namespace cop
  7. {
  8.     Bitmap::Bitmap(int width, int height) : m_width(width), m_height(height), m_pPixel(new uint8_t[width*height * 3]{})
  9.     {
  10.     }
  11.  
  12.     void Bitmap::setPixel(int x, int y, uint8_t red, uint8_t green, uint8_t blue)
  13.     {
  14.     }
  15.  
  16.     bool Bitmap::write(std::string filename)
  17.     {
  18.         cop::BitmapFileHeader fileHeader;
  19.         cop::BitmapInfoHeader infoHeader;
  20.  
  21.         //Size of file is size of Bitmap File Header + size of Bitmap Info Header + (3bytes each pixel will be taking)
  22.         fileHeader.fileSize = sizeof(cop::BitmapFileHeader) + sizeof(cop::BitmapInfoHeader) + m_width + m_height * 3;
  23.         //distance from the beginning of the file to where the data actually starts
  24.         fileHeader.dataOffset = sizeof(cop::BitmapFileHeader) + sizeof(cop::BitmapInfoHeader);
  25.  
  26.         infoHeader.width = m_width;
  27.         infoHeader.height = m_height;
  28.  
  29.         std::ofstream file;
  30.  
  31.         file.open(filename, std::ios::out | std::ios::binary);
  32.  
  33.         if (!file)
  34.         {
  35.             return false;
  36.         }
  37.  
  38.         file.write((char *)&fileHeader, sizeof(fileHeader));
  39.         file.write((char *)&infoHeader, sizeof(infoHeader));
  40.         file.write((char *)&m_pPixel.get(), m_width*m_height*3); //Error -> Expression must have an lvalue or a function designator
  41.  
  42.         file.close();
  43.    
  44.         if (!file)
  45.         {
  46.             return false;
  47.         }
  48.  
  49.         return true;
  50.     }
  51.  
  52.     Bitmap::~Bitmap()
  53.     {
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement