如何从HWND中删除以前的图像数据

问题描述:

我正在使用GDI +绘制具有透明度的png图像。



过了一段时间我想用一些旋转绘制相同的图像。但我无法删除上一个图像日期。所以我渲染的窗口是一系列旧图像。



I am using GDI+ to draw png image with transparency.

after sometime I want to draw same image with some rotation. but I am not able to remove The previous image date. So my rendered window is a series of old images.

void CBusyWnd::drawImage	( )
{
	if (mImage)
	{
		Gdiplus::Graphics gdip(mWnd);
		gdip.ResetTransform();
		gdip.TranslateTransform((Gdiplus::REAL)(mImage->GetWidth())/2.0f,(Gdiplus::REAL)(mImage->GetHeight())/2.0f);
		gdip.RotateTransform(mAngle=mAngle>360?0:mAngle+1);
		gdip.TranslateTransform(-1.0f*(Gdiplus::REAL)(mImage->GetWidth())/2.0f,-1.0f*(Gdiplus::REAL)(mImage->GetHeight())/2.0f);
		gdip.DrawImage(mImage, 0, 0, mImage->GetWidth(), mImage->GetHeight());
		gdip.Flush();
	}
	InvalidateRect(mWnd, NULL, FALSE);
}



请在http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/825a5243-9441-4abc-be30-e5598ccc9872 [ ^ ]



我的注册窗口类是: -




please find image at http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/825a5243-9441-4abc-be30-e5598ccc9872[^]

my registered window class is:-

outWndClass.style		= CS_HREDRAW | CS_VREDRAW;
outWndClass.lpfnWndProc		= wndProc; 
outWndClass.hInstance		= GetModuleHandle(NULL);
outWndClass.hCursor		= LoadCursor(NULL, IDC_APPSTARTING);
outWndClass.hbrBackground	= (HBRUSH)GetStockObject(HOLLOW_BRUSH);//(HBRUSH)(COLOR_WINDOW + 1);
outWndClass.lpszClassName	= L"BusyWnd";

outWndClass.hIcon		= LoadIcon(outWndClass.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));


if (!RegisterClass(&outWndClass))
{
	if (GetLastError() != 0x00000582) // already registered)
	{
		OutputDebugString(L"Unable to register class BusyWnd\n");
		return false;
	}
}





任何人都可以帮我一些指针。



我尝试在每次抽奖前使用以下代码清除窗口。但代码太慢,无法设置透明度。





Can anyone help give me some pointer.

I tried following code for clearing the window before each draw. but Code is too slow and the is no way to set transparency.

HDC hdc = GetDC(mWnd); // Get the DC from that HWND
for( UINT i = 0 ; i < mImage->GetWidth() ; i++ )
	for( UINT j = 0 ; j < mImage->GetHeight() ; j++ )
		SetPixel(hdc, i,j, RGB(255,255,255)); // SetPixel(HDC hdc, int x, int y, COLORREF color)
ReleaseDC(mWnd, hdc); // Release the DC
DeleteDC(hdc); // Delete the DC

现在你的代码正在做的是它没有清除.png图像的先前位置。您需要做的是每次需要重新加载背景图像然后定位.png。
Right now what your code is doing is its not clearing the previous position of .png image. What you need to do is every time you need to reload the background image and then position your .png .