The ImageViewer is very confusing because it’s described as something to show an image. I tried it and was happy to see that it resized the image when I resized the control. However, it has a border I can’t remove.
I found a post that said I should use a Canvas. But the Canvas doesn’t resize the (background) image. My need here is very common. Why isn’t there a resize option in the Canvas control?
I created this Paint function, after making a Subclass of Canvas:
// In the Paint event of the Canvas
if Canvas1.RealImage = Nil then
Canvas1.RealImage = Canvas1.Backdrop // Get the backdrop
Canvas1.Backdrop = nil // And then remove it
end if
If Canvas1.RealImage <> Nil Then
// Draw the image scaled to fit the Canvas
g.DrawPicture(Canvas1.RealImage, 0, 0, Canvas1.Width, Canvas1.Height, 0, 0, Canvas1.RealImage.Width, Canvas1.RealImage.Height)
End If
This is extremely frustrating. If I set a breakpoint and step through the code, then the result works. I have to step to the point where Backdrop is set to nil. If I don’t do that, then it draws both the scaled version and the original-size Backdrop.
The code should be executing whether or not there is a breakpoint!
I’m using the latest Xojo (4.2) which I just installed today.
let the backdrop nil in designer and in the inspector behavior make your picture property visible.
seems the backdrop is a computed property.
Canvas1.Width and g.Width
i would use the graphics context argument because you paint in this graphics.
and its better if you reuse the source code it not adress explicit a control.
there are other threads that show how to use correct picture ratio.
I agree, just wanted to be sure there was no actual difference. Your post about Inspector Behavior solved the problem. I moved the image from Backdrop to RealImage, making Backdrop nil. Thanks again.
I’m just waiting to see if anyone can clarify the debug behavior, which still seems like a bug.
the paint event draws on top of the Backdrop.
this Backdrop = nil create a new paint event.
generally avoid generate the same event in a event.
correctly source code would be if xojo create a row that paint the backdrop in the paint event and we can do what we like to do with it.
i added a feature request that we can visualize the backdrop self.