<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreImage",
  "identifier" : "/documentation/CoreImage/CIImage/cropped(to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Image"
    ],
    "preciseIdentifier" : "c:objc(cs)CIImage(im)imageByCroppingToRect:"
  },
  "title" : "cropped(to:)"
}
-->

# cropped(to:)

Returns a new image with a cropped portion of the original image.

```
func cropped(to rect: CGRect) -> CIImage
```

## Parameters

`rect`

The rectangle, in image coordinates, to which to crop the image.

## Return Value

An image object cropped to the specified rectangle.

## Discussion

![Butterfly photo with background cropped out](images/com.apple.coreimage/media-2951307@2x.png)

## Discussion

Due to Core Image’s coordinate system mismatch with [UIKit](https://developer.apple.com/library/archive/releasenotes/General/WhatsNewIniOS/Articles/iOS5.html#//apple_ref/doc/uid/TP30915195-SW41), this filtering approach may yield unexpected results when displayed in a <doc://com.apple.documentation/documentation/UIKit/UIImageView> with <doc://com.apple.documentation/documentation/UIKit/UIView/contentMode-swift.property>. Be sure to back it with a [`cgImage`](/documentation/CoreImage/CIImage/cgImage) so that it handles <doc://com.apple.documentation/documentation/UIKit/UIView/contentMode-swift.property> properly.

```swift
CIContext* context = [CIContext context];
CGImageRef cgCroppedImage = [context createCGImage:ciCroppedImage fromRect:ciCroppedImage.extent];
UIImage* croppedImage = [UIImage imageWithCGImage:cgCroppedImage];
CGImageRelease(cgCroppedImage);
```

If you are displaying or processing your image primarily as a <doc://com.apple.documentation/documentation/CoreGraphics/CGImage> or <doc://com.apple.documentation/documentation/UIKit/UIImage>, with no additional Core Image application, consider cropping in Core Graphics using the <doc://com.apple.documentation/documentation/CoreGraphics/CGImage/cropping(to:)> function to save processing overhead from conversion of images to [`CIImage`](/documentation/CoreImage/CIImage).  It makes most sense to use [`cropped(to:)`](/documentation/CoreImage/CIImage/cropped(to:)) when you already have [`CIImage`](/documentation/CoreImage/CIImage) in your pipeline.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)