Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello! I use StretchBlt to load bitmap image and show it on screen.
I also use double buffer in my application, which is dialog based.

I wrote a function that displays the image:

void CPlay::OnBackground(CBitmap* p, CDC* pDC)
{
    CDC dcMemory;
    BITMAP bm;
    dcMemory.CreateCompatibleDC(pDC);
    dcMemory.SelectObject(p);
    p->GetBitmap(&bm);

	pDC->StretchBlt(0, 0, screenX, screenY, &dcMemory, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
}


Then I make CBitmap variable and load the image:
variable.LoadBitmap(RESOURCE);


I call the function OnBackground(&variable, &pDC);
pDC is CDC variable;
screenX, screenY are my screen resolution:
	screenX = GetSystemMetrics(SM_CXSCREEN);
	screenY = GetSystemMetrics(SM_CYSCREEN);


If I keep my resol(1280x1024), it works well. But if I change it, my CPU starts using 50-60% and it is slowed down.
If I'm wrong using StretchBlt, please let me know.
I hope you can get my point, that's why I used to write it in a detailed manner.
Thanks!
Posted
Updated 16-Apr-10 21:14pm
v4

You may create at once a resized bitmap instead of stretching again and again the original one. See if my "Plain C Resampling DLL"[^] article helps.
:)
 
Share this answer
 
Do you mean AS you change it, or AFTER you change it ? If you're changing it, it's drawing the image over and over, so of course that uses the processor.
 
Share this answer
 
Try to clean your DC before you change your resolution. It will produce a great effect I believe.
 
Share this answer
 
It's not related to your question, but there is a conceptual error in your function: when you select a GDI object, like a bitmap onto a device context you must keep trace of the previously selected one and restore it, before destroying the device context.

C++
void CPlay::OnBackground(CBitmap* p, CDC* pDC)
{
    CDC dcMemory;
    BITMAP bm;
    dcMemory.CreateCompatibleDC(pDC);
    CBitmap *pOriginalBmp = dcMemory.SelectObject(p);
    p->GetBitmap(&bm);
	pDC->StretchBlt(0, 0, screenX, screenY, &dcMemory, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
    dcMemory.SelectObject(pOriginalBmp);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900