-2

Possible Duplicate:
Cropping a UIImage

I have one UIImage view,In that i need to crop some space in that UIImage view and need to store as Uiimage.And the pass to another view that saved image.

Community
  • 1
  • 1
12345
  • 157
  • 3
  • 10

2 Answers2

0

there are quite a few ways to crop images using the Core Graphics functions, the most basic one would be:

CGRect cropRect = CGRectMake(0, 0, 100, 100);
CGImageRef cropped_img = CGImageCreateWithImageInRect(yourUIImage.CGImage, cropRect)

Also please check below tutorial

How to Crop an Image (UIImage) On iOS

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
0

This might help. It's mostly copy-paste from my code.

I have a big UIImageView with the original image - mImageViewCropper, Then I have a semitransparent view, then a smaller UIImageView overlayed - mImageViewCropperSmallWindow. (it looks like the cropper in Instragram)

On pinchGesture and panGesture, I resize the small imageView, and then I call the following function, which loads into the small imageView the correspondant cropped image from the big picture.

-(void)refreshImageInMImageViewCropperSmallWindow
{
    double imageBeginX = 0; //we need to set these because of possible ratio mismatch (black stripes)
    double imageEndX = 0;
    double imageBeginY = 0;
    double imageEndY = 0;
    CGSize imageSize = mImageViewCropper.image.size;
    imageBeginX = mImageViewCropper.frame.size.width /2 - imageSize.width/2;
    imageEndX = mImageViewCropper.frame.size.width /2 + imageSize.width/2;
    imageBeginY = mImageViewCropper.frame.size.height /2 - imageSize.height/2;
    imageEndY = mImageViewCropper.frame.size.height /2 + imageSize.height/2;

    CGRect smallFrame = mImageViewCropperSmallWindow.frame;

    UIImage *croppedImage = [mImageViewCropper.image crop: CGRectMake(smallFrame.origin.x - imageBeginX, smallFrame.origin.y - imageBeginY, 
    smallFrame.size.width, smallFrame.size.height)];
    mImageViewCropperSmallWindow.image = croppedImage;        
}

-the method is far from perfect, but it's a starting point

codrut
  • 810
  • 10
  • 19