2

Rectangle used to crop

I am trying to crop an image using this rectangle.But Not getting how to stretch the rectangle.I am having one UIView that is outside and within that other view shown with black border. When I stretch DO i need to change the frame for both UIViews ??

should use Pinchgesture to stretch the rectangle or any other method??

Here four blue handlers are UIView s. How will i determine the dragging of them?? If there please suggest.

Heena
  • 2,348
  • 3
  • 32
  • 58
  • 2
    I have not done like this but here is some link which may be useful to you. : http://stackoverflow.com/questions/5880597/custom-image-mask-in-ios, http://stackoverflow.com/questions/7087435/image-cropping-api-for-ios, http://stackoverflow.com/questions/158914/cropping-a-uiimage – Devang Aug 17 '12 at 11:03
  • Check this link it contains which you you want : https://github.com/barrettj/BJImageCropper – Devang Aug 17 '12 at 11:09
  • @Devang I have already created rectangle for that.Just need to drag that and set – Heena Aug 17 '12 at 11:11
  • BJImageCropper will give you some idea. It contains that drag feature. – Devang Aug 17 '12 at 11:15
  • you jush need to assign a cropView and add gesture to it to resize it – Bala Aug 17 '12 at 17:22

1 Answers1

2

Following code for the selecting the box and cropping the image.

-(IBAction) cropImage:(id) sender{
    // Create rectangle that represents a cropped image  
    // from the middle of the existing image
float xCo,yCo;
float width=bottomCornerPoint.x-topCornerPoint.x;
float height=bottomCornerPoint.y-topCornerPoint.y;
if(width<0)
width=-width;
if(height<0)
    height=-height;
         if(topCornerPoint.x <bottomCornerPoint.x)
         {
               xCo=topCornerPoint.x;
          }
         else 
         {
             xCo=bottomCornerPoint.x;
         } 
        if(topCornerPoint.y <bottomCornerPoint.y)
        {
             yCo=topCornerPoint.y;
         }
      else {
             yCo=bottomCornerPoint.y;
       }
    CGRect rect = CGRectMake(xCo,yCo,width,height);
    // Create bitmap image from original image data,
    // using rectangle to specify desired crop area
    UIImage *image = [UIImage imageNamed:@"abc.png"];
    CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
    UIImage *img = [UIImage imageWithCGImage:imageRef]; 
    CGImageRelease(imageRef);
    // Create and show the new image from bitmap data
    imageView = [[UIImageView alloc] initWithImage:img];
    [imageView setFrame:CGRectMake(110, 600, width, height)];
    imageView.image=img;
    [[self view] addSubview:imageView];
    [imageView release];
}

Hope this may helping to lot

Suresh Varma
  • 9,750
  • 1
  • 60
  • 91
Nimit Parekh
  • 16,776
  • 8
  • 50
  • 72