---
title: "How to crop image in rectangle shape in iOS?"  
description: "How to crop image in rectangle shape in iOS?"  
author: "Anonymous User"  
published: 2016-01-20  
updated: 2016-01-20  
canonical: https://www.mindstick.com/forum/33905/how-to-crop-image-in-rectangle-shape-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# How to crop image in rectangle shape in iOS?

I am new in iPhone [app development](https://www.mindstick.com/services/mobile-app-development), so I have getting [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) on [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) cropping.\
I want to [crop](https://answers.mindstick.com/qa/32258/under-whose-chairmanship-a-regional-project-on-climate-resilience-building-among-farmers-through-crop-residue-management-has-launched) an image in rectangle shape, I [google](https://www.mindstick.com/articles/43833/google-lighthouse-and-how-is-it-changing-the-way-we-development-and-design-websites) it and find some solution for that and using this [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

```
CGRect cropRect = CGRectMake(0, 0, 70, 70);CGImageRef imageRef = CGImageCreateWithImageRect(self.OriginalImage, cropRect);
```

but I don't understand that how can I display imageRef into our [view controller](https://www.mindstick.com/forum/33709/how-to-use-table-view-controller-with-small-sized-in-ios).\
Please help me.

## Replies

### Reply by Tarun Kumar

For cropping the image one thing is very important to know that if we want to crop image then we need to convert that image into CGImage after that we can do anything with that image. after cropping the image in result cropped image will be saved into the CGImageRef reference variable.

Now, if we want to add cgimage into any [view](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-view) then we need to convert it into UIImage. below we are provided the complete code:

```
UIImage croppedImage = nil;CGRect cropRect = CGRectMake(0, 0, 70, 70);CGImageRef imageRef = CGImageCreateWithImageRect(self.OriginalImage, cropRect);// this is the code which is responsible for converting CGImage into UIImagecroppedImage = [UIImage imageWithCGImage:imageRef];CGImageRelease(imageRef);
```

I hope it will be helpful for you.


---

Original Source: https://www.mindstick.com/forum/33905/how-to-crop-image-in-rectangle-shape-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
