Я пытаюсь преобразовать UINT в шестнадцатеричный после чтения из изображения BMP - PullRequest
0 голосов
/ 01 мая 2020

Я пытаюсь прочитать изображение BMP на c ++ и выполнить некоторую обработку изображения на нем. то, что у меня есть:

#pragma once

#include <iostream>
#include <fstream>

namespace mybmp {
    class BMP
    {
    private:

    #pragma pack(push, 1)
        /*
            Without pragma pack(push, 1) the size of thus structures
            is 16 bytes, I need 14 bytes and it solves the problem
        */
        struct BMPFileHeader
        {
            uint16_t iFileType;
            uint32_t iFileSize;
            uint16_t iReserved1;
            uint16_t iReserved2;
            uint32_t iDataOffset;
        };

        struct BMPInfoHeader
        {
            uint32_t iFileSize;
            int32_t iFileWidth;
            int32_t iFileHeight;
            uint16_t iPlanes;
            uint16_t iBitCount;
            uint32_t iCompression;
            uint32_t iSize;
            int32_t iXPxPerMeter;
            int32_t iYPxPerMeter;
            uint32_t iColorUsed;
            uint32_t iColorImportant;
        };
    #pragma pack(pop)

        BMPFileHeader __BMPFileHeader;
        BMPInfoHeader __BMPInfoHeader;

    public:
        BMP(std::string fName);

        void imgRead(std::string fName);
        void tmpDataPrint();
    };
} // mybmp namespace end

и

#include "BMP.h"

mybmp::BMP::BMP(std::string fName)
{
    this->imgRead(fName);
}

void mybmp::BMP::imgRead(std::string fName)
{
    // Why I used the stream? Because I just have to read the file, that's all
    // https://www.tutorialspoint.com/cplusplus/cpp_files_streams.htm
    std::ifstream tmpFile(fName, std::ios::binary);
    if (tmpFile) {
        // Read file header section
        // Why I need size of? Cause I have to read just header section
        tmpFile.read((char*)&this->__BMPFileHeader, sizeof(this->__BMPFileHeader));
        if (__BMPFileHeader.iFileType != 0x4D42) {
            throw std::runtime_error("Error!\nCannot recognize file format!\n");
        }

        // Read info header section
        tmpFile.read((char*)&this->__BMPInfoHeader, sizeof(this->__BMPInfoHeader));
    }
}

Когда я печатаю его на консоль, я вижу что-то вроде: результат печати консоли Но то, что я хочу см. двоичная структура BMP

Как я могу преобразовать его из uintX_t в гекс? Мне это нужно для дальнейшей обработки пикселей и для понимания того, как работать с этим файлом. Спасибо за ваше время.

...