Estoy probando como puedo comparar si dos huellas en archivos bmp se pueden comparar, para ver si son iguales,
Encontre este link donde hay una funcion en c++ que compara dos bitmaps pero no funciona llamandolo desde codigo prg,
- Code: Select all Expand view
http://www.rqna.net/qna/mnwyqx-compare-two-bitmap-device-context-file.html
Y aqui el codigo que estoy usando :
- Code: Select all Expand view
/////////////////////////////////////////////////////////////////////////////
//
// CompareBitmaps
// Compares two HBITMAPs to see if they contain the same image
//
// Parameters :
// HBitmapLeft [in] : The HBITMAP handles that are to be compared
// HBitmapRight [in] :
//
// Returns :
// true if the bitmaps are the same
// false if they are different
//
/////////////////////////////////////////////////////////////////////////////
#include <hbapi.h>
#include <hbapiitm.h>
#include <winsock2.h>
#include <windows.h>
#include <string.h>
static bool CompareBitmaps(HBITMAP HBitmapLeft, HBITMAP HBitmapRight);
//-----------------------------------------------------------------------//
HB_FUNC( COMPAREBITMAPS )
{
HBITMAP hBitmapLeft = (HBITMAP) hb_parnl(1);
HBITMAP hBitmapRight= (HBITMAP) hb_parnl(2);
if ( CompareBitmaps( hBitmapLeft, hBitmapRight ) )
hb_retl( TRUE );
else
hb_retl( FALSE );
}
//-----------------------------------------------------------------------//
static bool CompareBitmaps(HBITMAP HBitmapLeft, HBITMAP HBitmapRight)
{
if (HBitmapLeft == HBitmapRight)
{
return true;
}
if (NULL == HBitmapLeft || NULL == HBitmapRight)
{
return false;
}
bool bSame = false;
HDC hdc = GetDC(NULL);
BITMAPINFO BitmapInfoLeft = {0};
BITMAPINFO BitmapInfoRight = {0};
BitmapInfoLeft.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BitmapInfoRight.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
if (0 != GetDIBits(hdc, HBitmapLeft, 0, 0, NULL, &BitmapInfoLeft, DIB_RGB_COLORS) &&
0 != GetDIBits(hdc, HBitmapRight, 0, 0, NULL, &BitmapInfoRight, DIB_RGB_COLORS))
{
// Compare the BITMAPINFOHEADERs of the two bitmaps
if (0 == memcmp(&BitmapInfoLeft.bmiHeader, &BitmapInfoRight.bmiHeader,
sizeof(BITMAPINFOHEADER)))
{
// The BITMAPINFOHEADERs are the same so now compare the actual bitmap bits
BYTE *pLeftBits = (BYTE*)hb_xgrab(sizeof(BYTE) * BitmapInfoLeft.bmiHeader.biSizeImage);
BYTE *pRightBits = (BYTE*)hb_xgrab(sizeof(BYTE) * BitmapInfoRight.bmiHeader.biSizeImage);
BYTE *pByteLeft = NULL;
BYTE *pByteRight = NULL;
PBITMAPINFO pBitmapInfoLeft = &BitmapInfoLeft;
PBITMAPINFO pBitmapInfoRight = &BitmapInfoRight;
// calculate the size in BYTEs of the additional
// memory needed for the bmiColor table
int AdditionalMemory = 0;
switch (BitmapInfoLeft.bmiHeader.biBitCount)
{
case 1:
AdditionalMemory = 1 * sizeof(RGBQUAD);
break;
case 4:
AdditionalMemory = 15 * sizeof(RGBQUAD);
break;
case 8:
AdditionalMemory = 255 * sizeof(RGBQUAD);
break;
case 16:
case 32:
AdditionalMemory = 2 * sizeof(RGBQUAD);
}
if (AdditionalMemory)
{
// we have to allocate room for the bmiColor table that will be
// attached to our BITMAPINFO variables
pByteLeft = new BYTE[sizeof(BITMAPINFO) + AdditionalMemory];
if (pByteLeft)
{
memset(pByteLeft, 0, sizeof(BITMAPINFO) + AdditionalMemory);
memcpy(pByteLeft, pBitmapInfoLeft, sizeof(BITMAPINFO));
pBitmapInfoLeft = (PBITMAPINFO)pByteLeft;
}
pByteRight = new BYTE[sizeof(BITMAPINFO) + AdditionalMemory];
if (pByteRight)
{
memset(pByteRight, 0, sizeof(BITMAPINFO) + AdditionalMemory);
memcpy(pByteRight, pBitmapInfoRight, sizeof(BITMAPINFO));
pBitmapInfoRight = (PBITMAPINFO)pByteRight;
}
}
if (pLeftBits && pRightBits && pBitmapInfoLeft && pBitmapInfoRight)
{
// zero out the bitmap bit buffers
memset(pLeftBits, 0, BitmapInfoLeft.bmiHeader.biSizeImage);
memset(pRightBits, 0, BitmapInfoRight.bmiHeader.biSizeImage);
// fill the bit buffers with the actual bitmap bits
if (0 != GetDIBits(hdc, HBitmapLeft, 0,
pBitmapInfoLeft->bmiHeader.biHeight, pLeftBits, pBitmapInfoLeft,
DIB_RGB_COLORS) && 0 != GetDIBits(hdc, HBitmapRight, 0,
pBitmapInfoRight->bmiHeader.biHeight, pRightBits, pBitmapInfoRight,
DIB_RGB_COLORS))
{
// compare the actual bitmap bits of the two bitmaps
bSame = 0 == memcmp(pLeftBits, pRightBits,
pBitmapInfoLeft->bmiHeader.biSizeImage);
}
}
// clean up
hb_xfree(pLeftBits);
hb_xfree(pRightBits);
hb_xfree(pByteLeft);
hb_xfree(pByteRight);
}
}
ReleaseDC(NULL, hdc);
return bSame;
}
Alguien tendra una solucion diferente o alguna sugerencia ?
PDTA : Estube buscando la funcion en "c" de fivewin "ReadBitmap" para usuarla en codigo "c", el wiki dice que se encuentra en el archivo "..\source\winapi\bmpread.c" pero no lo encuentro !!
Desde ya muchas gracias,
Saludos,