|
-
January 10th, 2007, 11:05 AM
#3
Re: Obtaining HBitmap from HDC
Thanks a lot. I have added the Bitblt and the new HDC and finally i have obtained the HBITMAP for the CStatic::SetBitmap function, so the refresh works well.
Code:
HBITMAP Asignar(CStatic *panel,HBITMAP imagen)
{
// Draw a HBITMAP into a CStatic
RECT r;
BITMAP bm;
GetObject(imagen,sizeof(BITMAP),&bm);
int Bps = bm.bmBitsPixel;
int Width = bm.bmWidth;
int Height = bm.bmHeight;
HBITMAP hResized_image;
panel->GetWindowRect(&r);
panel->ScreenToClient(&r);
HDC panel_hdc;
panel_hdc=panel->GetDC()->GetSafeHdc();
HDC DCOrigen = ::CreateCompatibleDC ( panel_hdc ); // DC for the image with the original size
HBITMAP hbitmap_anterior=(HBITMAP)::SelectObject(DCOrigen,imagen);
HDC hDC_new = ::CreateCompatibleDC ( panel_hdc );
hImagen_escalada = ::CreateCompatibleBitmap ( panel_hdc, r.right-r.left, r.bottom-r.top );
HGDIOBJ hOld = SelectObject(hDC_new, hResized_image);
StretchBlt(
hDC_new, // manipulador del contexto de dispositivo de destino
0, // coordenada x de la esquina superior izquierda del rectángulo de destino
0, // coordenada y de la esquina superior izquierda del rectángulo de destino
r.right-r.left, // anchura del rectángulo de destino
r.bottom-r.top, // altura del rectángulo de destino
DCOrigen, // manipulador del contexto de dispositivo de origen
0, // coordenada x de la esquina superior izquierda del rectángulo de origen
0, // coordenada y de la esquina superior izquierda del rectángulo de origen
Width , // anchura del rectángulo de origen
Height, // altura del rectángulo de origen
SRCCOPY // código de operación de rastreo
);
BitBlt(panel_hdc, 0, 0, r.right - r.left, r.bottom - r.top,hDC_new, 0, 0, SRCCOPY);
hResized_image= (HBITMAP)::SelectObject(hDC_new, hOld);
panel->SetBitmap(hResized_image); // it manage the image to be refreshed
::SelectObject(DCOrigen, hbitmap_anterior);
::DeleteDC(DCOrigen); // Destructora para CreateCompatibleDC
return hResized_image;
}
Only two more questions, why is neccesary other HDC? Is Bitblt really neccesary if i use SetBitmap? Well, thank you again :-) as i have said already works.
Last edited by Marc G; January 11th, 2007 at 01:10 PM.
Reason: Added code tags
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|