230490
230490

Reputation: 526

Black background with image in center using GDI

Im displaying an image in the center of window. However I want all the other area of the window to be black. How do I achieve this? Im using StretchBlt to center the image.Please advice

RECT clientRect,rect;
    HDC hDC = GetDC(hwnd);
    HDC hMemDC = CreateCompatibleDC(hDC);
    ::SelectObject(hMemDC, bmp);
    GetClientRect(hwnd, &clientRect);
StretchBlt(hDC, clientRect.left, clientRect.top, newwidth, newheight, hMemDC, 0, 0,bmpdata.bmWidth, bmpdata.bmHeight,SRCCOPY);

Upvotes: 1

Views: 298

Answers (1)

Jonathan Potter
Jonathan Potter

Reputation: 37152

Use ExcludeClipRect to clip out the area of the image, and then fill the background around it using FillRect.

Upvotes: 1

Related Questions