Cómo mostrar imágenes bmp en lenguaje c. Quiero completar el programa correcto, ¡lo necesito con urgencia!
lz ?Hola
Para mostrar mapas de bits bmp en lenguaje C, necesita usar la API de win32, como se muestra a continuación: BOOL?BitBlt( HDC?hdcDest,?//?Bitmap display Entorno del dispositivo de destino int?nXDest,?//?El mapa de bits que muestra la coordenada x del área del cliente int?nYDest,?//?La coordenada y del área del cliente que muestra el mapa de bits int?nWidth,?//?The ancho de la visualización del mapa de bits int?nHeight,?//?La longitud de la visualización del mapa de bits HDC?hdcSrc,?//?El entorno del dispositivo de origen (incluido el mapa de bits bmp que se mostrará) int?nXSrc, ///?La x inicial que se mostrará en el mapa de bits actual Posición int?nYSrc,//?La posición inicial y que se muestra en el mapa de bits actual DWORD?Modo de mapeo
);
El siguiente es el código fuente : //Mostrar mapa de bits bmp
#include
#include "resource.h"
LRESULT?CALLBACK?WndProc( HWND,? UINT,?WPARAM,? LPARAM);
void?DrawBrick();?
int?WINAPI?WinMain(HINSTANCE?hInstance,
HINSTANCE?hPrevInstance ,
PSTR?szCmdLine,
int?iCmdShow)
{
static TCHAR szAppName[]?=?TEXT("Bmp ");
HWND hwnd;
Mensaje MSG;
WNDCLASS wndclass;
wndclass.style =?CS_HREDRAW?|?CS_VREDRAW ;
wndclass .lpfnWndProc =?WndProc;
wndclass.cbClsExtra =?0;
wndclass.cbWndExtra =?0;
wndclass.hInstance =?hInstance ;
wndclass.hIcon =?LoadIcon(NULL,?IDI_APPLICATION);
wndclass.hCursor =?LoadCursor(NULL,?IDC_ARROW);
wndclass.hbrBackground =?(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName =?NULL;
wndclass.lpszClassName =?szAppName;
si(! RegisterClass(&wndclass))
{
MessageBox(NULL,?TEXT("¿Este?programa?requiere?Windows?NT!"),
szAppName, ?MB_ ICONERROR);
return?
}
hwnd?=?CreateWindow(szAppName,
TEXT("Bmp?Demo "),
WS_OVERLAPPEDWINDOW,
CW_USEDEF
AULT,
CW_USEDEFAULT,
754,
566,
NULL,
NULL,
hInstance,
NULL);
ShowWindow( hwnd,?iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,?NULL,?0,?0))
{
TranslateMessage(&msg).
DispatchMessage(&msg); p> p>
}
return?msg.wParam;
}
LRESULT? mensaje, WPARAM wParam, LPARAM lParam)
{
static HBITMAP hBitmap; //¿identificador del mapa de bits marcado con mapa de bits
static?int cxBitmap,?cyBitmap; //longitud y ancho del mapa de bits
BITMAP mapa de bits;
HDC hdc,?hdcMem;
HINSTANCE hInstance;
PAINTSTRUCT ps;
switch(mensaje) p>
{
case?WM_CREATE:
hInstance?=?((LPCREATESTRUCT)lParam)->hInstance; //Obtener el identificador de instancia de la ventana
hBitmap?=?LoadBitmap(hInstance,?MAKEINTRESOURCE(IDB_BITMAP1)); //carga el mapa de bits en la memoria
GetObject(hBitmap,?sizeof(BITMAP),? &bitmap);
cxBitmap?=?bitmap.bmWidth;//obtener la longitud del mapa de bits
cyBitmap?=?bitmap.bmHeight;//obtener el ancho del mapa de bits
retorno?
caso?WM_ PAINT:
hdc?=?BeginPaint(hwnd,? &ps);
hdcMem?=?CreateCompatibleDC(hdc) ;/ /¿crear un hdcMem compatible con la tabla de descriptores del entorno del dispositivo hdc? Se utiliza principalmente para tomar capturas de pantalla en la memoria
SelectObject(hdcMem,?hBitmap);//selecciona el mapa de bits en hdcMem
BitBlt(hdc,? -1,? -1,?cxBitmap,?cyBitmap,?hdcMem,?0,?0,?SRCCOPY);//pintar mapa de bits bmp
DeleteDC(hdcMem); p>
EndPaint(hwnd,? &ps);
re
¿girar?;
caso?WM_DESTROY:
DeleteObject(hBitmap);
PostQuitMessage(0);
retorno?; p> p>
}