I am trying to collect code to actually save an image from fingerprint sensors. I have already tried the forums and this is my current code that saves the file with the correct file size, but when I open the image, its not a fingerprint image is more like a damaged image. Here is how it looks.

My code is below. Any help would be appreciated. I am new to window design.
bool SaveBMP(BYTE* Buffer, int width, int height, long paddedsize, LPCTSTR bmpfile) { BITMAPFILEHEADER bmfh; BITMAPINFOHEADER info; memset(&bmfh, 0, sizeof(BITMAPFILEHEADER)); memset(&info, 0, sizeof(BITMAPINFOHEADER)); //Next we fill the file header with data: bmfh.bfType = 0x4d42; // 0x4d42 = 'BM' bmfh.bfReserved1 = 0; bmfh.bfReserved2 = 0; bmfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + paddedsize; bmfh.bfOffBits = 0x36; //and the info header: info.biSize = sizeof(BITMAPINFOHEADER); info.biWidth = width; info.biHeight = height; info.biPlanes = 1; info.biBitCount = 8; info.biCompression = BI_RGB; info.biSizeImage = 0; info.biXPelsPerMeter = 0x0ec4; info.biYPelsPerMeter = 0x0ec4; info.biClrUsed = 0; info.biClrImportant = 0; HANDLE file = CreateFile(bmpfile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); //Now we write the file header and info header: unsigned long bwritten; if (WriteFile(file, &bmfh, sizeof(BITMAPFILEHEADER), &bwritten, NULL) == false) { CloseHandle(file); return false; } if (WriteFile(file, &info, sizeof(BITMAPINFOHEADER), &bwritten, NULL) == false) { CloseHandle(file); return false; } //and finally the image data: if (WriteFile(file, Buffer, paddedsize, &bwritten, NULL) == false) { CloseHandle(file); return false; } //Now we can close our function with CloseHandle(file); return true; } HRESULT CaptureSample() { HRESULT hr = S_OK; WINBIO_SESSION_HANDLE sessionHandle = NULL; WINBIO_UNIT_ID unitId = 0; WINBIO_REJECT_DETAIL rejectDetail = 0; PWINBIO_BIR sample = NULL; SIZE_T sampleSize = 0; // Connect to the system pool. hr = WinBioOpenSession( WINBIO_TYPE_FINGERPRINT, // Service provider WINBIO_POOL_SYSTEM, // Pool type WINBIO_FLAG_RAW, // Access: Capture raw data NULL, // Array of biometric unit IDs 0, // Count of biometric unit IDs WINBIO_DB_DEFAULT, // Default database &sessionHandle // [out] Session handle ); // Capture a biometric sample. wprintf_s(L"\n Calling WinBioCaptureSample - Swipe sensor...\n"); hr = WinBioCaptureSample( sessionHandle, WINBIO_NO_PURPOSE_AVAILABLE, WINBIO_DATA_FLAG_RAW, &unitId, &sample, &sampleSize, &rejectDetail ); wprintf_s(L"\n Swipe processed - Unit ID: %d\n", unitId); wprintf_s(L"\n Captured %d bytes.\n", sampleSize); PWINBIO_BIR_HEADER BirHeader = (PWINBIO_BIR_HEADER)(((PBYTE)sample) + sample->HeaderBlock.Offset); PWINBIO_BDB_ANSI_381_HEADER AnsiBdbHeader = (PWINBIO_BDB_ANSI_381_HEADER)(((PBYTE)sample) + sample->StandardDataBlock.Offset); PWINBIO_BDB_ANSI_381_RECORD AnsiBdbRecord = (PWINBIO_BDB_ANSI_381_RECORD)(((PBYTE)AnsiBdbHeader) + sizeof(WINBIO_BDB_ANSI_381_HEADER)); PBYTE firstPixel = (PBYTE)((PBYTE)AnsiBdbRecord) + sizeof(WINBIO_BDB_ANSI_381_RECORD); SaveBMP(firstPixel, AnsiBdbRecord->HorizontalLineLength, AnsiBdbRecord->VerticalLineLength, AnsiBdbRecord->BlockLength, "D://test.bmp"); wprintf_s(L"\n Press any key to exit."); _getch(); }
windows visual-c ++ winapi
Abhishek sharma
source share