Gerard
Gerard

Reputation: 13397

How do you determine the actual size on screen?

In a wpf control with zoom functionality I calculate from the MouseWheelEventArgs how to scale the drawing canvas to implement the zoom effect.

Point mouse = e.GetPosition(myCanvas);
Matrix m = myCanvas.RenderTransform.Value;

if (e.Delta > 0)
{
    f = 1.1;
}
else
{
    f = 1.0 / 1.1;
}

m.ScaleAtPrepend(f, f, mouse.X, mouse.Y);
myCanvas.RenderTransform = new MatrixTransform(m);

I would like to know the actual size of one of the circles on the canvas. However Width, ActualWidth and such stay the same while zooming in and out (16.0). How would you determine (calculate?) the size of the circle that a user actually sees on his or her screen?

Upvotes: 2

Views: 390

Answers (1)

Matěj Zábský
Matěj Zábský

Reputation: 17272

MatrixTransform has a method TransformBounds for this. You feed it with original bounding box of the image (I think in your case 0,0,width,height will do) and it will return you its resulting bounding box.

Upvotes: 1

Related Questions