Bitmap scale to size of window issue

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
tatarinrafa
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sat Mar 12, 2022 8:46 pm

Bitmap scale to size of window issue

Post by tatarinrafa »

Hello!

Trying to stretch the bitmap to the size of window when painting

Initial call of paint event works fine, but after window got resized, painting gets glitched

Here is the code of paint event

Code: Select all


void wxImagePanel::OnPaintEvent(wxPaintEvent& evt)
{
	// depending on your system you may need to look at double-buffered dcs
	wxPaintDC dc(this);
	RenderImage(dc);
}

void wxImagePanel::RenderImage(wxDC& dc)
{
	if (image)
	{
		dc.SetUserScale((double)GetSize().x / (double)image->GetWidth(), (double)GetSize().y / (double)image->GetHeight());
		dc.DrawBitmap(*image, 0, 0, false);
	}
}

Initial painting https://ibb.co/BrWnZp7
Image

After window got resized https://ibb.co/smx7BXY
Image

Thanks in advance! :D
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Bitmap scale to size of window issue

Post by PB »

Drawing glitches appearing when the window is resized are often fixed by creating the window (wxImagePanel here) with wxFULL_REPAINT_ON_RESIZE flag.

Your drawing code should probably also account for possibility of image being null. If you do not call SetBackgroundStyle(wxBG_STYLE_PAINT) for your window and relying on the background erase, you should change that to avoid possible flicker. This makes you responsible for drawing the panel background, so you should do something when the bitmap is not available (e.g., calling wxDC::Clear()).
Post Reply