Skip to content

Instantly share code, notes, and snippets.

View sean7218's full-sized avatar
🛠️

Sean Zhang sean7218

🛠️
View GitHub Profile
@Digitalchemy
Digitalchemy / CropImage.cs
Created February 6, 2011 06:21
iOS: Crop a UIImage to the specified Rect
// Crop a UIImage to the specified cropRect
public UIImage CropImage(UIImage image, RectangleF cropRect)
{
UIGraphics.BeginImageContextWithOptions(cropRect.Size, false, 0);
var context = UIGraphics.GetCurrentContext();
context.TranslateCTM(0.0f, image.Size.Height);
context.ScaleCTM(1.0f, -1.0f);
context.DrawImage(new RectangleF(0, 0, image.Size.Width, image.Size.Height), image.CGImage);
context.ClipToRect(cropRect);