To understand what happens in this header file?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
30 views
The theme of the project - work with bmp images.
https://ru.wikipedia.org/wiki/BMP

C++ builder. In the header file bmp.h declares the structure of the class (and maybe a constructor?) and functions. Please explain how it all works, the beginner.

As this header file was connected to the project, just #include "bmp.h" or via the menu with++builder-a?

#include #include #pragma pack(1) struct FileHeader { WORD bfType; DWORD bfSize; WORD bfReserved1; //not used WORD bfReserved2; //not used DWORD bfOffbits; //offset bit data of the image header in bytes }; struct MAPINFO { DWORD Size; //number of bytes occupied by the structure of the InfoHeader DWORD Width; //width of bitmap image in pixels DWORD Height; //height of image bitmap in pixels WORD Planes; //number of bit planes device WORD BitCount; //number of bits per pixel DWORD Compression; //compression type DWORD SizeImage; //image size in bytes long XPelsPerMeter; //horizontal device resolution, pixel/m long YPelPerMeter; //vertical device resolution, pixel/m DWORD ClrUsed; //the number of colors used ClrImportant DWORD; //number of important colors }; struct RGBquad { BYTE rgbBlue; //intensity blue BYTE rgbGreen; //intensity of green BYTE rgbRed; //intensity of red BYTE rgbReserved; //not used }; class CBmp { private: void *pBmp; long SizeFile; public: CBmp(); ~CBmp(); void Open(char* fn); void Save(char* fn); FileHeader *GetFH(); MAPINFO *GetMapInfo(); RGBquad *GetMap(); }; void CBmp::Save(char* fn) { FILE* File; File=fopen(fn,"wb"); fwrite(pBmp,1,SizeFile,File); fclose(File); } RGBquad *CBmp::GetMap() { RGBquad *rgb; rgb=(RGBquad *)((long)pBmp+sizeof(FileHeader)+sizeof(MAPINFO)); return rgb; } MAPINFO *CBmp::GetMapInfo() { MAPINFO *mi; mi=(MAPINFO*)((long)pBmp+sizeof(FileHeader)); return mi; } FileHeader *CBmp::GetFH() { FileHeader *fh; fh=(FileHeader *)pBmp; return fh; } CBmp::CBmp() { pBmp=0; SizeFile=0; } CBmp::~CBmp() { delete [] pBmp; } void CBmp::Open(char* fn) { FILE* File; int hFile; File=fopen(fn,"rb"); hFile=_fileno(File); SizeFile=filelength(hFile); pBmp=(BYTE*)malloc(SizeFile); fread(pBmp,1,SizeFile,File); fclose(File); }


CLARIFICATION:
I want to understand the code above to do likewise structure
question: How to create a header file?

in my project I need to circle frame with a thickness of 15 pixels bmp image. The frame consists of pixels of random colors Working with graphics. C++ builder. How to draw a frame around the picture?
by | 30 views

1 Answer

0 like 0 dislike
Teach the concept of "unit of compilation". Here, unfortunately, there are things that should be in the. CPP file, and things should be in an. H file.

#pragma pack(1)
The data structure we need a "one to one" with no bytes of padding.

struct FileHeader struct MAPINFO

The BMP format. Do not forget that the BMP format is written with the bottom row!

The Open function reads the image "as is", Save writes "one to one", GetMapInfo, and GetFH give some titles of our BMP.

Remains GetMap(), which, in theory, should produce a matrix of colors, but really only works for 32-bit BMP and in no way encapsulates nor the width-height of the matrix, nor the fact that the BMP format is written with the bottom row.

This code is a C — minus.

Now, why your code does NOT, but, the idea needs to accomplish your objective.
1. Create a BMP of the right size from scratch, not loading from a file.
2. To encapsulate the matrix of pixels. It is advisable so that quick access strings as memory buffers, for ease of transfer of information from the old to the new BMP 30×30 pixels bigger.
3. If you limited support the format of BMP — exit with error if the version is unsupported (e.g., not the number of colors).

The task is on their own to support BMP? And then the Builder is TBitmap.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
36,634 users