2011-06-10 6 views

Répondre

2

je rogner l'image en même UIImageView

1) Stockez l'image uiimageview

2) Prenez la même UIImageView et le stocker sous forme UIImage

3) recadrer l'image et restaurer

Le code suivant vous aidera

- (IBAction) setCropItem: (id) sender {

UIGraphicsBeginImageContext(self.view.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *finishedPicForCrop = UIGraphicsGetImageFromCurrentImageContext(); 
CGImageRef imageRef = CGImageCreateWithImageInRect([finishedPicForCrop CGImage], CGRectMake(0, 45, 320, 420)); 
UIImage *img = [UIImage imageWithCGImage:imageRef]; 
CGImageRelease(imageRef); 
[firstImageView removeFromSuperview]; 
secondImageView = [[UIImageView alloc] initWithImage:img]; 
[secondImageView setFrame:CGRectMake(0, 0, 320, 460)]; 
scrollView.contentSize = secondImageView.bounds.size; 
[scrollView addSubview:secondImageView]; 

}

2

Il peut aider à vous

UIImage* whole = [UIImage imageNamed:@"whole.jpg"]; //I know this image is 300x300 


CGImageRef cgImg = CGImageCreateWithImageInRect(whole.CGImage, CGRectMake(x, y, 100, 100)); 
    UIImage* part = [UIImage imageWithCGImage:cgImg]; 
    UIImageView* Croppedimage = [[UIImageView alloc] initWithImage:part]; 

et Ci-dessous le lien plus-USEFULL

how to crop image in to pieces programmatically

Bonne chance

+1

Merci pour votre suggestion à J'ai trouvé la réponse samedi dernier. c'était comme ci-dessus code j'utilise CGImageCreateWithImageInRect() pour rogner une image mais j'ai utilisé pour stocker le uiimageview comme uiimage, puis recadrer l'image dans le même uiimageview – NandaKumar

+0

bienvenue et très bien :-) – NIKHIL

1

Si y Si vous avez besoin d'un contrôle d'interface utilisateur pour recadrer une image, essayez SSPhotoCropperViewController. C'est un contrôleur de vue personnalisé qui fournit une interface utilisateur simple, configurable et facile à utiliser pour recadrer et mettre à l'échelle des photos dans les applications iPhone. Il s'agit du tutorial et du source code on GitHub.

1
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{ 
// get touch event 
UITouch *touch = [[event allTouches] anyObject]; 
StartPoint = [touch locationInView:touch.view]; 
if (Img_Screen!=nil) { 
    [Img_Screen removeFromSuperview]; 
    Img_Screen=nil; 

} 

}

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

}

-(void)finishedTouchInside{ 

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

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

}

ici u peut rogner dans imageView et recadrée image sera affichée dans ImageViewNew

Questions connexes