2012-10-02 201 views
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; 
      } 
     } 
    } 

回答

0

我相信ContentMode決定如何縮放內容的預渲染版本。

但是,UIImageView根據UIImage的LeftCapWidth和TopCapHeight的參數決定如何縮放圖像,只有在未設置這些參數時才使用ContentMode。