Home > Software engineering >  How to turn a BYTE * array into BMP
How to turn a BYTE * array into BMP

Time:09-22

I have a big image block of the software is used to give, this is roughly like

Now there is a problem, I will take the picture above the red box in the first block of data, this have encapsulated by a DLL interface to, but it was to other algorithms, his interface is designed so
 
BYTE * StretchData the RECT (rt);


Taken out? That is to say the area is already give you the grey value of the drawing finished, originally pour a nothing important also, but later added a demand, need to put the picture form output to the memory, and I will a new fast memory BYTE to stretch, is roughly such,
 
Int * pucBuffer=new int [lBufferSize];
For (long long I=0; i {
PucBuffer [I]=RGB (bVal [I], bVal [I], bVal [I]);
}

Results a this bird toys

Obviously two problems, one is my drawing is wrong, the second is the picture down, guess BMP storage starting point does not agree with the way he BYTE * memory, his things from the top left corner and the BMP seems right

Here for a period of the BYTE array can be saved as a BMP code,

CodePudding user response:

Under the correct pictures for BMP like the bottom left,

CodePudding user response:

Originally is at the bottom of the first line in the DIB

CodePudding user response:

http://blog.csdn.net/why_up/article/details/12625389
Save BMP with this code

CodePudding user response:

refer to the second floor zgl7903 response:
originally is at the bottom of the first line in the DIB

Good friend means to achieve a flip horizontal myself? But the first stretch problem not solve

CodePudding user response:

Bi. BiBitCount= 32;
The other eight and under the bitmap and palette

CodePudding user response:

Hello, can add your WeChat or qq, programmers want to turned WeChat, hope predecessors to give some advice

CodePudding user response:

BMP data lines is low to the top of the order

CodePudding user response:

BMP data bytes are multiples of 4 in a row,

CodePudding user response:

Is there a BYTE * StretchData the RECT (rt); Code?

CodePudding user response:

BMP in memory from bottom to top on the right

CodePudding user response:

Void SaveBitmap (DWORD height, dwords width, char * pdata)
{
BITMAPFILEHEADER bmfHeader={0};
BITMAPINFOHEADER bi={0};

Bi. BiSize=sizeof (BITMAPINFOHEADER);
Bi. BiWidth=bmpScreen. BmWidth;
Bi. BiHeight=bmpScreen. BmHeight;
Bi. BiPlanes=1;
Bi. BiBitCount=32;
Bi. BiCompression=BI_RGB;
Bi. BiSizeImage=0;
Bi. BiXPelsPerMeter=0;
Bi. BiYPelsPerMeter=0;
Bi. The biClrUsed=0;
Bi. BiClrImportant=0;
DWORD dwBmpSize=((width * bi biBitCount + 31)/32) * 4 * height;

//Add the size of the headers to the size of the bitmap to get the total file size
DWORD dwSizeofDIB=dwBmpSize + sizeof (BITMAPFILEHEADER) + sizeof (BITMAPINFOHEADER);
//Offset to the where the actual bitmap bits start.
BmfHeader. BfOffBits=(DWORD) sizeof (BITMAPFILEHEADER) + (DWORD) sizeof (BITMAPINFOHEADER);

//the Size of the file
BmfHeader. BfSize=dwSizeofDIB;

//bfType must always be BM for Bitmaps
BmfHeader. BfType=0 x4d42;//BM

HANDLE hFile=CreateFile (L "test. BMP," GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD dwBytesWritten=0;
WriteFile (hFile, (LPSTR) & amp; BmfHeader, sizeof (BITMAPFILEHEADER), & amp; DwBytesWritten, NULL);
WriteFile (hFile, (LPSTR) & amp; Bi, sizeof (BITMAPINFOHEADER), & amp; DwBytesWritten, NULL);
WriteFile (hFile, LPSTR pdata, dwBmpSize, & amp; DwBytesWritten, NULL);
CloseHandle(hFile);
}
  • Related