【问题标题】:Image orientation in PopUp弹出窗口中的图像方向
【发布时间】:2014-05-13 07:33:36
【问题描述】:

我正在开发 Windows Phone 8 应用程序。

我有一个正在弹出窗口中显示的图像。但我有一些标准,比如。

if image width > image height - display in landscape mode 否则 display in portrait mode

那么我们怎样才能做到这一点呢?我搜索了这个,发现Popup没有方向属性。

double actualHeight = Application.Current.Host.Content.ActualHeight;
double actualWidth = Application.Current.Host.Content.ActualWidth;

 Grid grid = new Grid();
            grid.VerticalAlignment = VerticalAlignment.Center;
            grid.HorizontalAlignment = HorizontalAlignment.Center;
            grid.Height = actualHeight; //set height
            grid.Width = actualWidth; //set width
            grid.Background = new SolidColorBrush(Colors.White);

            Image img = new Image();
            img.VerticalAlignment = VerticalAlignment.Center;
            img.HorizontalAlignment = HorizontalAlignment.Center;
            img.Source = bitmapImage;
            img.Tap += OnFullScreenImageTap;

//below i am passing the calculated imageWidth and imageHeight

            if (imageWidth > imageHeight)
            {
                //Landscape
                Debug.WriteLine("Display image in LANDSCAPE");
            }
            else if (imageWidth == imageHeight)
            {
                //Portrait
                Debug.WriteLine("Display image in PORTRAIT");
            }
            else
            {
                //Portrait
                Debug.WriteLine("Display image in PORTRAIT");
            }
            grid.Children.Add(img);

            popUp.Child = grid; //set child content
            this.LayoutRoot.Children.Add(popUp);
            popUp.IsOpen = true;

编辑

这也是我尝试过的:

RotateTransform  rt = new RotateTransform();
            rt.CenterX = 20;
            rt.CenterY = 20;

            img.VerticalAlignment = VerticalAlignment.Center;
            img.HorizontalAlignment = HorizontalAlignment.Center;
            img.Source = bitmapImage;

            if (imageWidth > imageHeight)
            {
                //Landscape

                rt.Angle = 0;
                Debug.WriteLine("Display image in LANDSCAPE");
            }
            else if (imageWidth == imageHeight)
            {
                //Portrait

                rt.Angle = 90;
                Debug.WriteLine("Display image in PORTRAIT");
            }
            else
            {
                //Portrait
                rt.Angle = 90;
                Debug.WriteLine("Display image in PORTRAIT");
            }
            img.RenderTransform = rt;

【问题讨论】:

    标签: c# image silverlight windows-phone-8 windows-phone


    【解决方案1】:

    试试这个

            double actualHeight = Application.Current.Host.Content.ActualHeight;
            double actualWidth = Application.Current.Host.Content.ActualWidth;
    
            Grid grid = new Grid();
            grid.VerticalAlignment = VerticalAlignment.Center;
            grid.HorizontalAlignment = HorizontalAlignment.Center;
            grid.Height = actualHeight; //set height
            grid.Width = actualWidth; //set width
            grid.Background = new SolidColorBrush(Colors.White);
    
            Image img = new Image();
            img.VerticalAlignment = VerticalAlignment.Center;
            img.HorizontalAlignment = HorizontalAlignment.Center;
            img.Source = bitmapImage;
            img.Tap += OnFullScreenImageTap;
    
            RotateTransform rt = new RotateTransform
            rt.CenterX = actualWidth / 2;
            rt.CenterY = actualHeight / 2;
    
            if (imageWidth > imageHeight)
            {
                //Landscape
                rt.Angle = 0;
                Debug.WriteLine("Display image in LANDSCAPE");
            }
            else if (imageWidth == imageHeight)
            {
                //Portrait
                rt.Angle = 90;
                Debug.WriteLine("Display image in PORTRAIT");
            }
            else
            {
                //Portrait
                rt.Angle = 90;
                Debug.WriteLine("Display image in PORTRAIT");
            }
            grid.Children.Add(img);
    
            popUp.Child = grid; //set child content
            this.LayoutRoot.Children.Add(popUp);
            popUp.IsOpen = true;
    

    【讨论】:

    • 我已经尝试过这个和Landscape mode i have set rt.Angle = 0;,但它仍然是纵向显示的图像
    • 尝试设置 rt.Angle = 360;
    • 我猜你需要为旋转变换设置 CenterX & CenterY 属性,这将帮助你了解如何相对于原点进行旋转。 msdn.microsoft.com/en-us/library/…
    • 是的,它在添加 CenterX 和 CenterY 后可以工作,我有一个 40x40 的图像,我设置 CenterX 和 CenterY = 20,然后为纵向设置角度 = 90,为横向设置角度 = 0,它可以工作。
    • 请看我的编辑,它仍然只显示在portrait mode
    猜你喜欢
    • 2021-03-07
    • 2010-12-01
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多