0

我正在构建一个 MonoTouch 应用程序,该应用程序在 iOS 设备屏幕上具有 UI,并通过 HDMI 在第二个屏幕上显示图像。在 UIImageView 中显示图像时,图像不会填满第二个屏幕。下面是在外部屏幕上设置和显示图像的代码。UIScreen.Screens[1] 宽度和高度给了我正确的值 1920/1080。显示图像时,顶部/底部有 1 英寸边框,左/右有 1.5 英寸边框。使用具有类似外部屏幕设置的 MPMoviePlayerController 填充屏幕。

    public void SetImageExternal(string imageFile)
    {
        if(string.IsNullOrEmpty(imageFile) == false)
        {
            UIScreen externalScreen;
            UIWindow externalWindow;
            UIView externalView;
            UIImageView externalImageView;
            SizeF externalScreenSize;

            if(UIScreen.Screens.Length > 1)
            {

                if(externalWindow != null)
                    externalWindow.Dispose();
                externalWindow = null;

                externalScreenSize = new SizeF();
                externalScreenSize.Width = 0;
                externalScreenSize.Height = 0;
                UIScreenMode maxScreenMode = null;
                externalScreen = UIScreen.Screens[1];

                // Use the screen with the largest width
                for(int i = 0; i < externalScreen.AvailableModes.Length; i++)
                {       
                    UIScreenMode current = UIScreen.Screens[1].AvailableModes[i];
                    if(current.Size.Width > externalScreenSize.Width)
                    {
                        externalScreenSize = current.Size;
                        maxScreenMode = current;
                    }
                }

                externalScreen.CurrentMode = maxScreenMode;

                externalWindow = new UIWindow(new RectangleF(0, 0, externalScreenSize.Width, externalScreenSize.Height));
                externalWindow.RootViewController = new UIViewController(); // create dummy root view controller
                externalWindow.UserInteractionEnabled = false;

                externalImageView = new UIImageView(externalWindow.Frame);          
                externalImageView.Image = UIImage.FromBundle(imageFile);
                externalImageView.ContentMode = UIViewContentMode.ScaleToFill;

                externalView = new UIView(externalWindow.Frame);
                externalView.AddSubview(externalImageView);

                foreach(UIView view in externalWindow.Subviews)
                    view.RemoveFromSuperview();
                externalWindow.AddSubview(externalView);
                externalWindow.MakeKeyAndVisible();
                externalWindow.Hidden = false;
                externalWindow.Screen = externalScreen;
            }
        }
    }
4

1 回答 1

0

我相信 ContentMode 决定了内容的预渲染版本如何缩放。

但是 UIImageView 会根据 UIImage 的 LeftCapWidth 和 TopCapHeight 的参数来决定图像的缩放方式,只有在没有设置的情况下才会使用 ContentMode。

于 2012-10-12T15:58:56.167 回答