0

I'm making an application that need to crop the image to another image. i want to crop the source Image ( like green rectangle) to destination image ( like white rectangle). I can get the size of source and destination image and the offset x and y . How can i got that crop image and save it to library? You can see the image attach here:

enter image description here

How can I crop to that image? and if you can please give me an example source code so much thanks for that

Rajesh
  • 10,318
  • 16
  • 44
  • 64
Hieu Duc Pham
  • 1,074
  • 1
  • 10
  • 24

2 Answers2

0

Use this method and pass image, rect as parameter. You can specify y offset and x offset in cropRect

-(UIImage *)cropImage:(UIImage *)image rect:(CGRect)cropRect
{
   CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], cropRect);
   UIImage *cropedImg = [UIImage imageWithCGImage:imageRef]; 
   CGImageRelease(imageRef);
   return cropedImg;
}
Rajesh
  • 10,318
  • 16
  • 44
  • 64
-1

Check Below Code:

-(UIImage *)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize
{

UIGraphicsBeginImageContext(newSize); 

[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];  

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();   

UIGraphicsEndImageContext();   

return newImage;
}

Check below Links For reference:

  1. http://code4app.net/ios/Image-crop-demo/501e1f3f6803faea5d000000

  2. http://code4app.net/ios/Photo-Cropper-View-Controller/4f95519c06f6e7d870000000

  3. http://code4app.net/ios/Image-Cropper/4f8cc87f06f6e7d86c000000

  4. http://code4app.net/ios/Simple-Image-Editor-View/4ff2af4c6803fa381b000000

Get sample code from here. Then you can customise your own.

PREMKUMAR
  • 8,283
  • 8
  • 28
  • 51
  • Please understand the disadvantages of link-only answers and [why they are discouraged](http://stackoverflow.com/help/how-to-answer) on SO. – Nikolai Ruhe Aug 26 '14 at 07:26