private static RotateMode GetRotateMode(PictureOrientation pictureOrientation) { switch (pictureOrientation) { case PictureOrientation.Rotated90: return(RotateMode.Rotate270); case PictureOrientation.Rotated180: return(RotateMode.Rotate180); case PictureOrientation.Rotated270: return(RotateMode.Rotate90); default: return(RotateMode.None); } }
/// <summary> /// Sets the orientation of the device. /// </summary> /// <param name='requiredOrientation'> /// The desired orientation. /// </param> private void SetOrientation(PictureOrientation requiredOrientation) { if (this.orientationSetter == null) { this.orientationSetter = new Selector("setOrientation:"); } bool changeResolution = false; UIInterfaceOrientation newOrientation = UIInterfaceOrientation.Portrait; if (requiredOrientation == PictureOrientation.Landscape) { if (UIDevice.CurrentDevice.Orientation != UIDeviceOrientation.LandscapeLeft && UIDevice.CurrentDevice.Orientation != UIDeviceOrientation.LandscapeRight) { newOrientation = UIInterfaceOrientation.LandscapeLeft; changeResolution = true; } } else { if (UIDevice.CurrentDevice.Orientation != UIDeviceOrientation.Portrait && UIDevice.CurrentDevice.Orientation != UIDeviceOrientation.PortraitUpsideDown) { newOrientation = UIInterfaceOrientation.Portrait; changeResolution = true; } } if (changeResolution) { Messaging.void_objc_msgSend_int(UIDevice.CurrentDevice.Handle, this.orientationSetter.Handle, (int)newOrientation); } }
/// <summary> /// Start painting a new image /// </summary> /// <param name='orientation'> /// The orientation of the new image /// </param> private void NewImage(PictureOrientation orientation) { // If the device is still mid turn then the reported width and height may be wrong - hence we are using // Math.Max and Math.Min to ensure we get the right size. [Actually I've delayed the turning until we are // ready to display the app (inside call to EditImage) so it wouldn't have turned yet anyway] ImageStateData imageStateData = null; int deviceWidth = (int)UIScreen.MainScreen.Bounds.Width * this.deviceScale; int deviceHeight = (int)UIScreen.MainScreen.Bounds.Height * this.deviceScale; if (orientation == PictureOrientation.Landscape) { imageStateData = new ImageStateData(Math.Max(deviceHeight, deviceWidth), Math.Min(deviceHeight, deviceWidth), UndoRedoBufferSize); } else { imageStateData = new ImageStateData(Math.Min(deviceHeight, deviceWidth), Math.Max(deviceHeight, deviceWidth), UndoRedoBufferSize); } this.EditImage(Guid.NewGuid(), imageStateData); }