How can offset the Canvas.Backdrop

Hello,

Is it possible to offset the Canvas.Backdrop?

Sometimes a picture is dropped on to the canvas and the backdrop starts at 0,0.

Can I set it to 12, 24 instead? Actually, I would like to centre it.

I know that is much easier in an ImageWell, but is it possible in a canvas?

Thanks.

Lennox

I think the easiest solution would be to use the paint event instead of the backdrop property. There you can calculate your picture’s position and size completely free.

Use a temporary Picture to draw your image in, then you attribute that Picture to the Backdrop.

Clear ?

Thanks Ulrich, I’ll try that.

Thanks again.

Lennox

Thanks Emile,

Ulrich Suggestion seems better, but I will try both.

Thanks again.

Lennox

With two hands, it is easier to answer.

Create an offscreen picture,
Draw (using Picture1.Graphics.DrawPicture …) your image at the X,Y location you want,
Then use Canvas1.Backdrop = Picture1.

This answers your original question.

Remember: drawing your image in the Paint event requires a test against Nil on your image (to avoid crashes).

Hello,
to center an image in a canvas I use this method:

[code]Public Sub Picture_Scale(g as Graphics, the_Picture as Picture, the_Padding as Integer)
if the_Picture = nil then
// log(CurrentMethodName, “the_Picture = nil”)
Return
end if

dim Ratio as Double
dim xDisplacement as Integer
dim yDisplacement as Integer
dim CanvasAspectRatio as Double
dim PictureAspectRatio as Double

dim gAvailableWidth as Integer
dim gAvailableHeight as Integer

gAvailableWidth = g.Width - (the_Padding * 2)
gAvailableHeight = g.Height - (the_Padding * 2)

CanvasAspectRatio = (gAvailableWidth / gAvailableHeight)
PictureAspectRatio = the_Picture.Width / the_Picture.Height

Ratio = Min(gAvailableWidth / the_Picture.Width, gAvailableHeight / the_Picture.Height)

if CanvasAspectRatio <= PictureAspectRatio then

yDisplacement = Floor((g.Height * 0.5) - (the_Picture.Height * Ratio * 0.5))
g.DrawPicture(the_Picture, the_Padding, yDisplacement, the_Picture.Width * Ratio, the_Picture.Height * Ratio, 0, 0, the_Picture.Width, the_Picture.Height)

else

xDisplacement = Floor((g.Width * 0.5) - (the_Picture.Width * Ratio * 0.5))
g.DrawPicture(the_Picture, xDisplacement, the_Padding, the_Picture.Width * Ratio, the_Picture.Height * Ratio, 0, 0, the_Picture.Width, the_Picture.Height)

end if

End Sub[/code]

In the Paint-event of the canvas I call the method like this:

Picture_Scale(g, thePicture, 2)

Thanks Christian, works great.

Thanks again.

Lennox