Artifacts on screenshot from wxScreenDC and wxWindowDC

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
baralgin
In need of some credit
In need of some credit
Posts: 8
Joined: Mon Aug 23, 2010 10:41 am

Artifacts on screenshot from wxScreenDC and wxWindowDC

Post by baralgin »

Hello.
I need to save screenshot from my application ( this = wxFrame ). The code below does it but around the application icon (in the title bar) I see some artifacts. I suppose it is a result of wxImage::ClearAlpha() method and artifacts are the trace of icon's shadow or something like this. If I comment ClearAlpha than the image not recognized correctly by most of the picture viewers (only icon or title bar is shown, depends on OS). At the same time file contains all data (mspaint by winxp show the image). What would you recommend in this situation?

Code: Select all

	wxImage::AddHandler(new wxPNGHandler);

	wxWindowDC wnd(this);
	//wxScreenDC wnd;

	wxSize wndsize = wnd.GetSize();
	wxBitmap scr(wndsize.x, wndsize.y, -1);
	wxMemoryDC memdc(scr);
	memdc.Blit(0, 0, wndsize.x, wndsize.y, &wnd, 0, 0);
	memdc.SelectObject(wxNullBitmap);

	wxImage img = scr.ConvertToImage();
	img.ClearAlpha();

	img.SaveFile(wxT("c:\\baralgin\\my_screenshot.png"),wxBITMAP_TYPE_PNG);
ps: I tested this code on WinXP and Win7 (classic theme was used on both windows). There is no difference between wxScreenDC and wxWindowDC.
Post Reply