Loading

Tuesday, February 1, 2011

Crop Image From ImageView by touch

#pragma mark touches Working
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
// get touch event
UITouch *touch = [[event allTouches] anyObject];
StartPoint = [touch locationInView:touch.view];

}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// get touch event
UITouch *touch = [[event allTouches] anyObject];
EndPoint = [touch locationInView:touch.view];
}

-(IBAction)BtnDoneTouchInside
{

CGFloat width=EndPoint.x-StartPoint.x;
CGFloat hieght=EndPoint.y-StartPoint.y;
CGRect myImageRect = CGRectMake(StartPoint.x, StartPoint.y, width, hieght);
UIImageView *Img_Screen= [[UIImageView alloc] initWithFrame:myImageRect];

CGImageRef imageRef = CGImageCreateWithImageInRect([ImgMain.image CGImage], myImageRect);
// or use the UIImage wherever you like
[Img_Screen setImage:[UIImage imageWithCGImage:imageRef]];
CGImageRelease(imageRef);
[CropImageView addSubview:Img_Screen];

}

No comments:

Post a Comment