[C con Clase] Ayuda con el RGBQUAD del bitmap
Brian
brian.trujillo.mendez en gmail.com
Vie Mayo 3 22:22:36 CEST 2013
Me gustaria como ver el array de RGBQUAD de los bitsmap para poder compararlos, pero no se como hacerlo, he desarrollado un codigo pero no se como seguir , lo dejo aquí, lo he intentado todo, espero recibir ayuda.
#include <Windows.h>
class Bitmap
{
private:
HBITMAP handleBitmap;
BITMAPINFOHEADER CabeceraBitmap;
RGBQUAD MatrizBitmap;
public:
Bitmap(HDC hDC, LPTSTR FileName)//constructor a partir de un archivo
{
CrearBitmap(hDC, FileName);
}
//Funciones para obtener informacion del mapa de bits
int ObtenerAncho() {return CabeceraBitmap.biWidth; };
int ObtenerAltura() {return CabeceraBitmap.biHeight; };
WORD ObtenerProfundidad() {return CabeceraBitmap.biBitCount; };
DWORD ObtenerTamanioImagen() {return CabeceraBitmap.biSizeImage; };
//crear el bitmap
BOOL CrearBitmap(HDC hDC, LPTSTR FileName)
{
//Lectura del archivo, crea el handle al archivo
HANDLE hFile = CreateFile(FileName,
GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
return false;
BITMAPFILEHEADER CabeceraBitmapAux;
DWORD LeerBytes;
//Leer la cabecera del archivo del Bitmap
BOOL bOK = ReadFile(hFile,
&CabeceraBitmapAux, sizeof(BITMAPFILEHEADER),
&LeerBytes, NULL);
if ( (!bOK) || (LeerBytes != sizeof(BITMAPFILEHEADER) ) || (CabeceraBitmapAux.bfType != 0x4D42) )
{
//el mapa de bits debe ser tipo 0x4D42
//el puntero leerBytes debe llegar al final del bitma
//y debe leer el archivo correctmente
//sino cierra el handle o manipulador
CloseHandle(hFile);
return false;
}
BITMAPINFO * InfoCabeceraBitmap = (new BITMAPINFO);
//Puntero al buffer de la información de la cabecera.
if(InfoCabeceraBitmap != NULL)
{ //Lee la informacion de la cabecera y guardarla en el buffer.
bOK = ReadFile(hFile, InfoCabeceraBitmap, sizeof(BITMAPINFO),
&LeerBytes, NULL);
if ( (!bOK) || (LeerBytes != sizeof(BITMAPINFO) ) )
{
//Si no lo lee correctamente cerrar el handle o manipulador.
CloseHandle(hFile);
return false;
}
//Almaena el tamaño del mapa de bits en
//las variables miembro del objeto
CabeceraBitmap = InfoCabeceraBitmap->bmiHeader;
//puntero al buffer de bits donde se
//insertara toda la información del
//
BYTE * LeerBits;
//DIB_RGB_COLORS indica que BITMAPINFO
//contiene una matriz RGB()
//se informa la dirección en donde estará
//los bytes del bitmap, pero aún
//no se han leído
handleBitmap = CreateDIBSection(hDC,
InfoCabeceraBitmap, DIB_RGB_COLORS,
(PVOID*)&LeerBits, NULL, 0);
//crear el handle del bitmap utilizando la
//variable miembro
//Copia los bits
if ( (handleBitmap != NULL) && (LeerBits != NULL) )
{
//coloca el puntero al inicio del archivo
SetFilePointer(handleBitmap, CabeceraBitmapAux.bfOffBits,
NULL, FILE_BEGIN);
//Aqui se lee el archivo y se copian los bits en el buffer LeerBits.
bOK = ReadFile(hFile, LeerBits, InfoCabeceraBitmap->bmiHeader.biSizeImage,
&LeerBytes, NULL);
if (bOK)
return true;
}
}
return false;
}
};
//Prototipo
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
//Variables globales
int x = 0;
int y = 0;
int AnchoVentana;
int AlturaVentana;
HDC hDCAux;
HBITMAP g_Bitmap;
Bitmap * ladron;
//Funciones auxiliares
bool CrearVentana(HINSTANCE hInstancia, HWND& hVentana, UINT Ancho, UINT Altura, LPCWSTR ClaseVentana, LPCWSTR TituloVentana, int& nCmdShow);
void Inicializar(HWND hVentana);
void PintarDispositivoDeContexto(HDC hDC);
bool controles();
int WINAPI wWinMain(HINSTANCE hInstancia, HINSTANCE hInstaciaPrev, LPWSTR lpszCmdParam, int nCmdShow )
{
HWND hVentana;
MSG Mensaje;
CrearVentana(hInstancia, hVentana, 500, 500,L"Mi Ventana", L"Practica 1", nCmdShow);
HDC hDCPant = GetDC(hVentana); //creo el dispositivo de contexto compatible con la ventana creada
ladron = new Bitmap(hDCPant ,TEXT("ladron6.bmp"));
while(TRUE == GetMessage(&Mensaje, 0, 0, 0))
{
if (PeekMessage(&Mensaje, NULL, 0, 0, PM_REMOVE) )
{
if (Mensaje.message == WM_QUIT)
break;
TranslateMessage(&Mensaje);
DispatchMessage(&Mensaje);
}
else
{
PintarDispositivoDeContexto(hDCAux);
BitBlt(hDCPant, 0, 0, AnchoVentana, AlturaVentana, hDCAux, 0, 0, SRCCOPY);
ReleaseDC(hVentana, hDCPant);
}
}
return Mensaje.wParam;
}
bool CrearVentana(HINSTANCE hInstancia, HWND& hVentana, UINT Ancho, UINT Altura, LPCWSTR ClassName, LPCWSTR WindowName, int& nCmdShow)
{
WNDCLASSEX ClaseVentana;
ClaseVentana.hInstance = hInstancia;
ClaseVentana.lpszClassName = ClassName;
ClaseVentana.lpfnWndProc = WindowProcedure;
ClaseVentana.style = CS_HREDRAW || CS_VREDRAW;
ClaseVentana.cbSize = sizeof(WNDCLASSEX);
ClaseVentana.hIcon = LoadIcon(NULL, IDI_APPLICATION);
ClaseVentana.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
ClaseVentana.hCursor = LoadCursor(NULL, IDC_ARROW);
ClaseVentana.lpszMenuName = NULL;
ClaseVentana.cbClsExtra = 0;
ClaseVentana.cbWndExtra = 0;
ClaseVentana.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1);
if (!RegisterClassEx(&ClaseVentana))return false;
if (ClaseVentana.lpszMenuName != NULL)
AlturaVentana += GetSystemMetrics(SM_CYMENU);
AnchoVentana = Ancho + GetSystemMetrics(SM_CXFIXEDFRAME)*2;
AlturaVentana = Altura + GetSystemMetrics(SM_CYFIXEDFRAME)*2;
int X = (GetSystemMetrics(SM_CXSCREEN) - AnchoVentana) / 2;
int Y = (GetSystemMetrics(SM_CYSCREEN) - AlturaVentana) / 2;
hVentana = CreateWindowEx(0,
ClassName,
WindowName,
WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX,
X, Y,
AnchoVentana, AlturaVentana,
NULL,
NULL,
hInstancia,
NULL);
if(!hVentana)
return false;
ShowWindow(hVentana, nCmdShow);
UpdateWindow(hVentana);
return true;
}
LRESULT CALLBACK WindowProcedure(HWND hVentana, UINT Mensaje, WPARAM wParam, LPARAM lParam)
{
switch(Mensaje)
{
case WM_CREATE:
Inicializar(hVentana);
break;
case WM_DESTROY:
DeleteObject(hDCAux);
DeleteObject(g_Bitmap);
PostQuitMessage(0);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hVentana, &ps);
PintarDispositivoDeContexto(hDC);
EndPaint(hVentana, &ps);
break;
}
return DefWindowProc(hVentana, Mensaje, wParam, lParam);
}
void Inicializar(HWND hVentana)
{
HDC hDC;
hDC = GetDC(hVentana);
hDCAux = CreateCompatibleDC(hDC);
g_Bitmap = CreateCompatibleBitmap(hDC, AnchoVentana, AlturaVentana);
SelectObject(hDCAux, g_Bitmap);
DeleteObject(hDC);
}
void PintarDispositivoDeContexto(HDC hDC)
{
}
void Controles()
{
}
Más información sobre la lista de distribución Cconclase