C#winrt scale和translate ellipse

时间:2014-08-01 08:23:36

标签: c# windows-runtime zoom scale translate

我使用Windows运行时在C#中开发。我有一个带有scrollviewer的图像。在这张图片上,我动态制作椭圆。当我缩放图像时,省略号不会缩放。我想知道如何缩放椭圆以保持良好的位置。

我的代码:

List<Point> pTmp = new List<Point>();
Point positionOrigine = new Point();

if(tabPointOrig == null)
{
    tabPointOrig = new List<Point>();
    tabPointOrig = tabPoint;
}

foreach(Point p in tabPointOrig)
{
    pTmp.Add(new Point(
        Math.Round(p.X - Scroll.HorizontalOffset),
        Math.Round(p.Y - Scroll.VerticalOffset)));
}

tabPoint = pTmp;

foreach(var Can in GridImage.Children)
{
    if(Can.GetType() == typeof(Canvas))
    {
        Canvas CanTmp = (Canvas)Can;

        foreach (var CanElement in CanTmp.Children)
        {
            TransformGroup TG = new TransformGroup();
            TranslateTransform trans = new TranslateTransform();
            ScaleTransform scale = new ScaleTransform();

            positionOrigine = new Point(
                Canvas.GetLeft(CanElement),
                Canvas.GetTop(CanElement));

            #region Deplacement des point
            //On deplace les points de réserve en même temps que l'image
            trans.X = Scroll.HorizontalOffset * -1;
            trans.Y = Scroll.VerticalOffset * -1;
            #endregion

            #region Zoom des points
            //On zoom les points de réserve en même temps que l'image
            ZoomFactor = Scroll.ZoomFactor;
            scale.ScaleX = scale.ScaleY = scale.ScaleX * ZoomFactor;
            #endregion

            TG.Children.Add(scale);
            TG.Children.Add(trans);

            //On applique les changements a l'image
            CanElement.RenderTransform = TG;

            #region Point Sorti du Grid
            //On regarde si le point sort du grid
            if ((Canvas.GetLeft(CanElement) + trans.X + (30 * ZoomFactor)) < 0 ||
                (Canvas.GetTop(CanElement) + trans.Y + (30 * ZoomFactor)) < 0
                )
                Can.Visibility = Visibility.Collapsed;
            else
                Can.Visibility = Visibility.Visible;
            #endregion
        }
    }
}

0 个答案:

没有答案