public UIImage Crop(UIImage image, RectangleF section) { // Start context. UIGraphics.BeginImageContext(section.Size); var ctx = UIGraphics.GetCurrentContext(); // Clear the image with red. ctx.SetRGBFillColor(255, 255, 255, 255); ctx.FillRect(new RectangleF(new PointF(0, 0), section.Size)); // Setting transform to flip the image. var transform = new MonoTouch.CoreGraphics.CGAffineTransform(1, 0, 0, -1, 0, section.Height); ctx.ConcatCTM(transform); // Drawing the image. var drawSource = CreateDrawRectangle(image, section); ctx.DrawImage(drawSource, image.CGImage.WithImageInRect(section)); // Extracting the image and ending. var croppedImage = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); return croppedImage; }
private void MirrorImage() { UIGraphics.BeginImageContext(profilePicture.Size); var ctx = UIGraphics.GetCurrentContext(); ctx.TranslateCTM(profilePicture.Size.Width, 0); ctx.ScaleCTM(-1, 1); var transform = new MonoTouch.CoreGraphics.CGAffineTransform(1, 0, 0, -1, 0, profilePicture.Size.Height); ctx.ConcatCTM(transform); ctx.DrawImage(new RectangleF(new PointF(0, 0), profilePicture.Size), profilePicture.CGImage); profilePicture = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); profilePictureView.Image = profilePicture; }