Created
March 22, 2011 22:29
-
-
Save follesoe/882223 to your computer and use it in GitHub Desktop.
MonoTouch example of cropping an image.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Where is CreateDrawRectangle() ? I can't seem to find it.
Where is CreateDrawRectangle() ? I can't seem to find it.
Where is CreateDrawRectangle() ? I can't seem to find it.
Where is CreateDrawRectangle() ? I can't seem to find it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where is CreateDrawRectangle() ? I can't seem to find it.
Update: I believe it is defined in this source file
https://github.com/follesoe/FacebookBigProfile/blob/761ae309df72b12864f6e91115bb2932ab264978/FacebookBigProfile/MainView.xib.cs#L492