2

I've tried several methods here on stackoverflow, and the closest one is the following:

Border DesignBorder = new Border();
DesignBorder.BorderThickness = new System.Windows.Thickness(2.0);
DesignBorder.BorderBrush = Brushes.Black;

GeneralTransform transform = Selected.TransformToVisual(canvasDrawingArea);
Rect R = transform.TransformBounds(new Rect(0, 0, Selected.ActualWidth, Selected.ActualHeight));

DesignBorder.SetValue(Canvas.LeftProperty, R.Left);
DesignBorder.SetValue(Canvas.TopProperty, R.Top);
DesignBorder.SetValue(Canvas.WidthProperty, R.Width);
DesignBorder.SetValue(Canvas.HeightProperty, R.Height);

canvasDrawingArea.Children.Add(DesignBorder);

Selected is the image that has been rotated.

When the Image is rotated in increments of 90 degrees, everything looks great. However, at 45, 135, etc. degrees, the bounding box is not nearly close enough

picture link for 90 degrees

enter image description here

picture link for 45 degrees

enter image description here

Is this just the best that can be done? Or is there a way to improve the bounding box?

EDIT:

I thought it was working find for 90 degree rotates, but it only gave the appearance of working as the image I was working with was nearly a square. As soon as I put a more rectangular image in, it became obvious that 90 degree increments also do not work.

  • 1
    A better method would have to know about the transparent background of the image, i.e. where the image is transparent and where not. You may however replace images by geometry drawings. – Clemens Dec 15 '13 at 09:47
  • Use RenderTransform.Here are few links: http://msdn.microsoft.com/en-us/library/system.windows.media.transform.transformbounds(v=vs.110).aspx http://msdn.microsoft.com/en-us/library/system.windows.uielement.rendertransform(v=vs.110).aspx – dev hedgehog Dec 15 '13 at 12:20
  • @devhedgehot, I like the rotation better for RenderTransform, but the border goes completely crazy when I try transforming the border using Selected.RenderTansform.TransformBounds(currentR) --currentR being the current Bounds-- It is nowhere near the 45 degree rotated image – Bobby Steele Dec 15 '13 at 21:52
  • @Clemens So would creating a modified image class that has a geometry rectangle bounds in the background help solve the issue? – Bobby Steele Dec 15 '13 at 21:58

0 Answers0