I have included my code below. I am trying to size the image to the client area size of a frame and then.draw the jpg image on the client area of the frame.
The code below only produces a frame with a grey background. Why am I not getting my image?
wx.ClientDC is meant for transitory/temporary drawing not for things that need to be visible long term. Those things need to be drawn from a wx.EVT_PAINT event. In addition, any drawing done while a window is not visible is basically ignored on most platforms.
So what is happening in your example is that nothing is drawn, then the frame is shown, then there is a EVT_PAINT event, and the default paint handler simply draws the frame’s default background. My suggestion is to continue to load the image and convert to a wx.Bitmap in the frame’s __init__ method, saving it in an attribute of self, like self.bmp. Then you can bind an event handler for wx.EVT_PAINT and in that handler create a wx.PaintDC and call its DrawBitmap method. You may also want to add a wx.EVT_SIZE event handler and rescale your image to the new frame size.
Oh, one more thing:
frame_size = self.GetSize()
A frame’s size is not necessarily the size available for drawing in (think about the frame’s possible borders and caption bar). You should probably use GetClientSize here.
Thank you! All is working except when resizing I see the original picture and artifacts for each redwaw. Am I missing something to perhaps clear the area before a redraw? I thought it would just overwrite.
Edit: Nevermind. The redraw needed ClientDC instead of PaintDC. All is well now. Thank you so much for your help.